我通過SOAP調用獲得以下XML。將編碼的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#,如果下面是一個完整的混亂我的appologies。
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);
感謝破折號,你的代碼像一個魅力工作。我會用一個引用,但我需要保持所有的代碼內聯;沒有代碼背後。 – primortal