我有一个XML如下面的XML,遍历在c#
<product>
<ProductId>3</ProductId>
<ProductName>Voice Recognition</ProductName>
</product>
<product>
<ProductId>5</ProductId>
<ProductName>TravelExpert Settings</ProductName>
<ProductAttribute>
<Name>AllowbookIncompleteTraveller</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>CreateTravs</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>MultiPax</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>Hotel</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>Profile</Name>
<Description>true</Description>
</ProductAttribute>
<ProductAttribute>
<Name>Air</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>TicketDelivery</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>Exchange</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>Car</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>Itinerary</Name>
<Description>false</Description>
</ProductAttribute>
<ProductAttribute>
<Name>StoredFare</Name>
<Description>false</Description>
</ProductAttribute>
</product>
我需要遍历与产品名称=“TravelExpert设置”产品,其下我需要ProductAttribute的值与名称=“资料”。值是真的。元素的类型是System.Xml.Linq.XElement。
我可以请这个帮忙吗?如果您需要进一步说明,请告诉我。
非常感谢。
谢谢!
夫妇的选择。您可以使用[.NET序列化支持](http://msdn.microsoft.com/en-us/library/58a18dwa(v = vs.110).aspx),并简单地对对象建模,反序列化,然后使用LINQ查找你需要的价值。第二种选择是使用[XPath](http://msdn.microsoft.com/en-us/library/ms256086(v = vs.110).aspx)查找所需的节点。 – LB2
是的,我与之合作的团队对这些概念并不是很了解。这是我的第一个建议。 – OBL