<?xml version="1.0" encoding="UTF-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><GetXmlDocumentResponse xmlns="http://tempuri.org/">
<GetXmlDocumentResult>
<SNR_JO_POST xmlns="">
<Sectors>
<LawyerName> abc</LawyerName>
<ID>{B263A7B1-D766-4308-B486-C63BE66F4D74}</ID>
<Email>abc@gmail.com</Email>
</Sectors>
</SNR_JO_POST>
</GetXmlDocumentResult>
</GetXmlDocumentResponse>
</soap:Body>
</soap:Envelope>
以上是soap响应,我想从响应中获取LawyerName,ID和Email的值。 我如何在我的c#代码中使用此响应。
答案 0 :(得分:1)
您可以将Linq To Xml用于此
var xDoc = XDocument.Parse(xmlstring);
var sectors = xDoc.Descendants("Sectors").FirstOrDefault();
var lawyerName = (string)sectors.Element("LawyerName");
var id = (string)sectors.Element("ID");