我再次遇到XML文檔問題,我通過網絡請求(HP Service Manager)收到回覆。如何正確處理此XML響應(SOAP:Envelope)以獲取至少一個DataView/DataTable?
這是XML響應:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<RetrieveSDToDoListResponse
message="Success" returnCode="0"
schemaRevisionDate="2015-09-24"
schemaRevisionLevel="0" status="SUCCESS"
xmlns="http://schemas.hp.com/SM/7"
xmlns:cmn="http://schemas.hp.com/SM/7/Common"
xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.hp.com/SM/7 /SDToDo.xsd">
<instance query="" recordid="CM00106862 - cm3r" uniquequery="record.id="CM00106862" and itemType="cm3r"">
<TodoNumber type="String">CM00106862</TodoNumber>
<ToDoModule type="String">cm3r</ToDoModule>
<ToDoStatus type="String">submitted</ToDoStatus>
<ToDoDescription type="String">Portactivation Server SCHWARTZ3 C6000 Request and Network Configuration Request</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">p591392</ToDoAssigneeName>
</instance>
<instance query="" recordid="IM02086084 - probsummary" uniquequery="record.id="IM02086084" and itemType="probsummary"">
<TodoNumber type="String">IM02086084</TodoNumber>
<ToDoModule type="String">probsummary</ToDoModule>
<ToDoStatus type="String">In Charge</ToDoStatus>
<ToDoDescription type="String">WBI-FN Operating rights for XL10033 expired?</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">p707112</ToDoAssigneeName>
</instance>
<instance query="" recordid="IM02135674 - probsummary" uniquequery="record.id="IM02135674" and itemType="probsummary"">
<TodoNumber type="String">IM02135674</TodoNumber>
<ToDoModule type="String">probsummary</ToDoModule>
<ToDoStatus type="String">In Charge</ToDoStatus>
<ToDoDescription type="String">G00PSMP1: Event ID: 432, FILE, ERROR => SollShares => 430 => 432</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">p518731</ToDoAssigneeName>
</instance>
<instance query="" recordid="TM00059273 - cm3t" uniquequery="record.id="TM00059273" and itemType="cm3t"">
<TodoNumber type="String">TM00059273</TodoNumber>
<ToDoModule type="String">cm3t</ToDoModule>
<ToDoStatus type="String">submitted</ToDoStatus>
<ToDoDescription type="String">Tributum Server Downtime - Tivoli Task</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">xl10033</ToDoAssigneeName>
</instance>
<instance query="" recordid="TM00059274 - cm3t" uniquequery="record.id="TM00059274" and itemType="cm3t"">
<TodoNumber type="String">TM00059274</TodoNumber>
<ToDoModule type="String">cm3t</ToDoModule>
<ToDoStatus type="String">submitted</ToDoStatus>
<ToDoDescription type="String">Tributum disable mainframe ressource</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">xl10033</ToDoAssigneeName>
</instance>
<instance query="" recordid="TM00059278 - cm3t" uniquequery="record.id="TM00059278" and itemType="cm3t"">
<TodoNumber type="String">TM00059278</TodoNumber>
<ToDoModule type="String">cm3t</ToDoModule>
<ToDoStatus type="String">submitted</ToDoStatus>
<ToDoDescription type="String">Tributum Server Downtime - Tivoli Task</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">xl10033</ToDoAssigneeName>
</instance>
<instance query="" recordid="TM00059280 - cm3t" uniquequery="record.id="TM00059280" and itemType="cm3t"">
<TodoNumber type="String">TM00059280</TodoNumber>
<ToDoModule type="String">cm3t</ToDoModule>
<ToDoStatus type="String">submitted</ToDoStatus>
<ToDoDescription type="String">Tributum disable mainframe ressource</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">xl10033</ToDoAssigneeName>
</instance>
<instance query="" recordid="TM00059504 - cm3t" uniquequery="record.id="TM00059504" and itemType="cm3t"">
<TodoNumber type="String">TM00059504</TodoNumber>
<ToDoModule type="String">cm3t</ToDoModule>
<ToDoStatus type="String">submitted</ToDoStatus>
<ToDoDescription type="String">Tributum disable mainframe ressource</ToDoDescription>
<ToDoAssignmentGroup type="String">XL/IOC GERMANY</ToDoAssignmentGroup>
<ToDoAssigneeName type="String">p568003</ToDoAssigneeName>
</instance>
</RetrieveSDToDoListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我試圖與下面的代碼,但我通過循環通現有節點是在末端。 我知道應該有一個簡單的方法來從節點「實例」和所有子項目獲取所有項目。
最後,我需要一個DataView或一個DataTable繼續我的應用程序。
public static string gettextfromWebserviceItems(string result)
{
StringBuilder builder = new StringBuilder();
var doc = new XmlDocument();
doc.LoadXml(result);
var ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
//XmlNodeList nodes = doc.SelectNodes("/SOAP-ENV:Envelope/SOAP-ENV:Body/RetrieveSDToDoListResponse/instance", ns);
XmlNodeList nodes = doc.GetElementsByTagName("instance");
List<string> elementNamesList = new List<string>();
elementNamesList.Add("TodoNumber");
elementNamesList.Add("ToDoModule");
elementNamesList.Add("ToDoStatus");
elementNamesList.Add("ToDoDescription");
elementNamesList.Add("ToDoAssignmentGroup");
elementNamesList.Add("ToDoAssigneeName");
foreach (XmlNodeList node in nodes)
{
//foreach (XmlAttribute v in node.Attributes)
//{
// var value = v;
// //Do the processing
//}
}
如果沒有與像SAX或任何一個外部DLL一個簡單的解決方案,所以讓我知道...
謝謝你在前進, ,距離慕尼黑
你嘗試_add服務Reference_的項目,並自動生成一組類的?這很容易,不需要手動分析肥皂信封。 –