XDocument.Element returns null when parsing an xml string

后端 未结 4 2081
悲哀的现实
悲哀的现实 2021-01-18 09:43

I have this xml string:



        
4条回答
  •  梦谈多话
    2021-01-18 10:25

    Here is correct way to get prices:

    var xdoc = XDocument.Parse(xmlString);
    XNamespace ns = xdoc.Root.GetDefaultNamespace();
    
    var pricres = from o in xdoc.Root.Elements(ns + "offers").Elements(ns + "offer")
                  select (int)o.Element(ns + "price");
    

    Keep in mind that your document have default namespace, and a is also namespace.

提交回复
热议问题