How to get xml element values to a string using Xdocument

后端 未结 2 825
忘了有多久
忘了有多久 2021-01-28 06:33

I am storing a xml in a string and using Xdocument i am parsing the string to xml from that i need to get xml element values and using that values i need to insert it in db. Any

相关标签:
2条回答
  • 2021-01-28 06:56

    Use this:

    string value = xd.Root.Element("SellerSKU").Value;
    
    0 讨论(0)
  • 2021-01-28 07:17

    You should use the xml namespace http://mws.amazonaws.com/FulfillmentInventory/2010-10-01/

    var xDoc = XDocument.Parse(xml);
    XNamespace ns = "http://mws.amazonaws.com/FulfillmentInventory/2010-10-01/";
    
    var condition = (string)xDoc.Descendants(ns + "Condition").First();
    

    OR

    you can search for Tag Condition in any xml namespace

    var condition2 = (string)xDoc.Descendants()
                                 .First(d => d.Name.LocalName == "Condition");
    

    OR

    you can use XPath to get Condition in any xml namespace

    var condition3 = (string)xDoc.XPathSelectElement("//*[local-name()='Condition']");
    
    0 讨论(0)
提交回复
热议问题