I am trying to get the values for faultcode, faultstring, and OrderNumber from the SOAP below
Yes, you're ignoring the XML namespace when selecting:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
.....
<m:SaveOrder xmlns:m="http://www.test.com/software/schema/" UserGUID="test">
<Order OrderNumber="1234-1234-123" Caller="" OrderStatus="A" xmlns="http://www.test.com/software/schema/">
The <Order>
tag is inside the <m:SaveOrder>
tag which uses the XML namespace prefixed by the m:
prefix.
Also, you're trying to select the "detail" and then you skip to the "Order" node directly (using .Elements()
) - you missed the <m:SaveOrder>
node in between.
You need to take that into account when selecting:
XDocument doc = XDocument.Load(HttpContext.Current.Server.MapPath("XMLexample.xml"));
XNamespace xmlns = "http://www.test.com/software/schema/";
var orderNode = doc.Descendants(xmlns + "SaveOrder").Elements(xmlns + "Order");
var value = from o in orderNode.Attributes("OrderNumber")
select o.Value;
Does that give you a result??