c# 如何读取xml 多级子节点里的值?
<?xmlversion="1.0"encoding="UTF-8"?>-<TestItem><Name>Capacitorpolaritytest</Name>-<Op...
<?xml version="1.0" encoding="UTF-8"?>
-<TestItem>
<Name>Capacitor polarity test</Name>
-<Operation>
-<OperationList>
<Description>Switch Bat On</Description>
<TestCommand>$Switch_Bat-H</TestCommand>
<ShowMessage>#Switch_Bat-H,ok</ShowMessage>
</OperationList>
</Operation>
</TestItem>
要读取<Name>和<OperationList>的值,怎么读取? 展开
-<TestItem>
<Name>Capacitor polarity test</Name>
-<Operation>
-<OperationList>
<Description>Switch Bat On</Description>
<TestCommand>$Switch_Bat-H</TestCommand>
<ShowMessage>#Switch_Bat-H,ok</ShowMessage>
</OperationList>
</Operation>
</TestItem>
要读取<Name>和<OperationList>的值,怎么读取? 展开
1个回答
展开全部
var xml = new XmlDocument();
xml.LoadXml(xmlString);
string name = xml.SelectSingleNode("/TestItem/Name").InnerText;
Console.WriteLine(name);
string desc = xml.SelectSingleNode("/TestItem/Operation/OperationList/Description").InnerText;
Console.WriteLine(desc);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询