Eksempel paa parsning af SOAP XML:
using System;
using System.Xml;
namespace E
{
public class Program
{
public static void Main(string[] args)
{
string xmlresponse =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=""
http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ns1=""
http://etdomaine.dk/ws/CRM"" xmlns:xsd=""
http://www.w3.org/2001/XMLSchema"" xmlns:ns2=""
http://xml.apache.org/xml-soap"" xmlns:xsi=""
http://www.w3.org/2001/XMLSchema-instance"" xmlns:SOAP-ENC=""
http://schemas.xmlsoap.org/soap/encoding/"" SOAP-ENV:encodingStyle=""
http://schemas.xmlsoap.org/soap/encoding/""><SOAP-ENV:Body>
<ns1:createCustomerResponse>
<returnvalue xsi:type=""ns2:Map"">
<item>
<key xsi:type=""xsd:string"">text</key>
<value xsi:type=""xsd:string"">Parameter 11 (land) should be 2 letters</value>
</item>
<item>
<key xsi:type=""xsd:string"">code</key>
<value xsi:type=""xsd:int"">0</value>
</item>
</returnvalue>
</ns1:createCustomerResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlresponse);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("SOAP-ENV", "
http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("ns1", "
http://etdomaine.dk/ws/CRM");
string text = doc.SelectSingleNode("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:createCustomerResponse/returnvalue/item[key='text']/value", nsmgr).FirstChild.Value;
int code = int.Parse(doc.SelectSingleNode("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:createCustomerResponse/returnvalue/item[key='code']/value", nsmgr).FirstChild.Value);
Console.WriteLine(text);
Console.WriteLine(code);
}
}
}