How to Read a specific element value from XElement in LINQ to XML

前端 未结 3 1094
感情败类
感情败类 2021-01-12 09:31

I have an XElement which has content like this.


   
         


        
3条回答
  •  生来不讨喜
    2021-01-12 09:52

    XElement response = XElement.Load("file.xml"); // XElement.Parse(stringWithXmlGoesHere)
    XNamespace df = response.Name.Namespace;
    XElement status = response.Element(df + "Status");
    

    should suffice to access the Status child element. If you want the value of that element as a string then do e.g.

    string status = (string)response.Element(df + "Status");
    

提交回复
热议问题