我通过 SOAP 调用获得了以下 XML。
<?xml version="1.0" encoding="utf-8"?>
<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>
<GetValueListForFieldResponse xmlns="http://URLHere/webservices/">
<GetValueListForFieldResult>
&lt;SelectDef&gt; &lt;Id&gt;1736&lt;/Id&gt; &lt;SelectName&gt;Values List&lt;/SelectName&gt; &lt;GlobalFlag&gt;False&lt;/GlobalFlag&gt; &lt;Sort&gt;1&lt;/Sort&gt; &lt;SelectDefValues&gt; &lt;SelectDefValue&gt; &lt;guid&gt;aaf6f3a7-6a74-4187-b4e7-3a9355b16796&lt;/guid&gt; &lt;Id&gt;14692&lt;/Id&gt; &lt;Name&gt;Open&lt;/Name&gt; &lt;Description&gt;&lt;/Description&gt; &lt;Color&gt;#000000&lt;/Color&gt; &lt;DefaultFlag&gt;False&lt;/DefaultFlag&gt; &lt;SortOrder&gt;1&lt;/SortOrder&gt; &lt;select_id&gt;1736&lt;/select_id&gt; &lt;/SelectDefValue&gt; &lt;SelectDefValue&gt; &lt;guid&gt;f5082b54-d799-4fdc-80c1-0e232b360057&lt;/guid&gt; &lt;Id&gt;14693&lt;/Id&gt; &lt;Name&gt;Closed&lt;/Name&gt; &lt;Description&gt;&lt;/Description&gt; &lt;Color&gt;#000000&lt;/Color&gt; &lt;DefaultFlag&gt;False&lt;/DefaultFlag&gt; &lt;SortOrder&gt;0&lt;/SortOrder&gt; &lt;select_id&gt;1736&lt;/select_id&gt; &lt;/SelectDefValue&gt; &lt;SelectDefValue&gt; &lt;guid&gt;94e29e78-2ab3-463f-bbb6-ab7f36003c7f&lt;/guid&gt; &lt;Id&gt;14780&lt;/Id&gt; &lt;Name&gt;Past Due&lt;/Name&gt; &lt;Description&gt;&lt;/Description&gt; &lt;Color&gt;#000000&lt;/Color&gt; &lt;DefaultFlag&gt;False&lt;/DefaultFlag&gt; &lt;SortOrder&gt;2&lt;/SortOrder&gt; &lt;select_id&gt;1736&lt;/select_id&gt; &lt;/SelectDefValue&gt; &lt;/SelectDefValues&gt; &lt;/SelectDef&gt;
</GetValueListForFieldResult>
</GetValueListForFieldResponse>
</soap:Body>
有没有办法将 GetValueForFieldResult 节点中的数据转换为实际的 XML,以便我可以解析数据?
下面是我如何进行 SOAP 调用和存储 XML。我正在学习 C#,如果下面是一团糟,我的道歉。
HttpWebRequest reqVl = (HttpWebRequest)WebRequest.Create(serverURL + "/ws/Field.asmx");
reqVl.Headers.Add("SOAPAction", "http://URL/webservices/GetValueListForField");
reqVl.ContentType = "text/xml;charset=\"utf-8\"";
reqVl.Accept = "text/xml";
reqVl.Method = "POST";
using (Stream stm = reqVl.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(VLsoap);
}
}
WebResponse responseVL = reqVl.GetResponse();
Stream responseStreamVL = responseVL.GetResponseStream();
XmlReader rdrVL = XmlReader.Create(responseStreamVL);
XmlDocument vls = new XmlDocument();
vls.Load(rdrVL);