Using C# to parse a SOAP Response

前端 未结 1 1889
野的像风
野的像风 2020-12-18 12:41

I am trying to get the values for faultcode, faultstring, and OrderNumber from the SOAP below



        
1条回答
  •  温柔的废话
    2020-12-18 13:12

    Yes, you're ignoring the XML namespace when selecting:

    
       .....
       
         
    

    The tag is inside the 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 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??

    0 讨论(0)
提交回复
热议问题