Parse and query SOAP in C#

…衆ロ難τιáo~ 提交于 2019-12-04 16:57:49

If you're trying to build an XName with a namespace you need to build it from an XNamespace plus a string, e.g.

XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
XName body = soapenv + "Body";

Then when you use the XName "body" with Linq-to-XML it will match the <soapenv:Body> element in your document.

You can do similar things to allow building the names of other elements with namespaces.

There's an even simpler way. You can simply specify the namespace inline using {} notation:

var soap = XElement.Load(soapPath);
var transactionID = 
        from e in soap.Descendants("{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2}TransactionID")
        select e.Value;

I think you will need to use XmlDocument (for reading the XML) and XmlNamespaceManager (for retreiving the namespace data) and using XPath queries from those objects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!