我的代码如下:
XDocument xmlDoc = XDocument.Load("myXML.xml");
var data = from items in xmlDoc.Root.Elements("category")
where items.Attribute("value").Value == "idxCategoryPlatformEngine"
select new
{
attribute = items.Element("attributes").Element("attribute").Element("name").Value,
trigger = items.Element("attributes").Element("attribute").Element("trigger").Value,
value = items.Element("attributes").Element("attribute").Element("value").Value,
minutes = items.Element("attributes").Element("attribute").Element("minutes").Value
};
我拥有的XML如下:
<?xml version="1.0" encoding="utf-8"?>
<GMS>
<category value="idxCategoryPlatformEngine">
<attributes>
<attribute>
<name>CheckpointFileCorruptionAlarm.InAlarm</name>
<trigger>EQ</trigger>
<value>TRUE</value>
<minutes>0</minutes>
</attribute>
<attribute>
<name>CPULoad</name>
<trigger>GT</trigger>
<value>60</value>
<minutes>5</minutes>
</attribute>
<attribute>
<name>Engine.Historian.InStoreForward</name>
<trigger>EQ</trigger>
<value>TRUE</value>
<minutes>0</minutes>
</attribute>
</attributes>
</category>
<category value="idxCategoryApplicationEngine">
<attributes>
<attribute>
<name>CheckpointFileCorruptionAlarm.InAlarm</name>
<trigger>EQ</trigger>
<value>TRUE</value>
<minutes>0</minutes>
</attribute>
<attribute>
<name>CPULoad</name>
<trigger>GT</trigger>
<value>60</value>
<minutes>5</minutes>
</attribute>
<attribute>
<name>Engine.Historian.InStoreForward</name>
<trigger>EQ</trigger>
<value>TRUE</value>
<minutes>0</minutes>
</attribute>
</attributes>
</category>
</GMS>
现在,当我运行代码时,它确实执行了查询,但是它只返回我真正想要所有属性的第一个属性。
我将不胜感激任何帮助,因为它让我发疯,我为尝试解决此问题所做的每一次更改只会导致更多问题!