且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LINQ to XML-读取XML文档

更新时间:2022-11-27 22:39:44

还不清楚,或者您还没有解释您感兴趣的数据.但是,当前选择的"OrderRequest"元素似乎并不具有您尝试访问的任何属性或子元素,所以我怀疑这样做

Well it is not clear or rather you have not explained which data you are interested in. However the "OrderRequest" element you currently select does not seem the one having any of the attributes or child elements you are trying to access so I suspect doing

var itemOut = from c in xdoc.Descendants("ItemOut")

                               select new
                               {
                                   SupplierID = c.Element("ItemID").Element("SupplierPartID").Value                               ,
                                   Currency = c.Element("ItemDetail").Element("UnitPrice").Element("Money").Attribute("currency").Value,
                                   Money = (double)c.Element("ItemDetail").Element("UnitPrice").Element("Money"),
                                   Description = c.Element("ItemDetail").Element("Description").Value,
                                   ManufacturerPartID = c.Element("ItemDetail").Element("ManufacturerPartID").Value
                               };

更接近您想要实现的目标.我无法弄清楚您想要哪个外部"元素,因此我将其遗漏了.

is closer to what you want to achieve. I couldn't figure which "Extrinsic" element you want so I left that out.