我想要输入值(funName)并检查XML文件属性(FunName),然后输出XML文件属性(isEnable)boolean true或false如何从XML返回布尔值获取值?
如何修改此代码?
我的XML文件
<itema>
<itemb FunName="ABC" isEnable="true"></itemb>
<itemb FunName="DEF" isEnable="false"></itemb>
</itema>
我的代码
public bool FunEnable(string funName , string isEnable)
{
bool result = true;
XmlDocument xDL = new XmlDocument();
xDL.Load("C://XMLFile2.xml"); //Load XML file
XmlNode xSingleNode = xDL.SelectSingleNode("//itemb");
XmlAttributeCollection xAT = xSingleNode.Attributes; //read all Node attribute
for (int i = 0; i < xAT.Count; i++)
{
if (xAT.Item(i).Name == "isEnable")
{
Console.WriteLine(xAT.Item(i).Value); //read we want attribute content
}
}
return result;
}
非常感谢
你*有*使用XmlDocument的? LINQ to XML使这个微不足道的...(不可否认,从你已经得到的代码中得到结果并不难 - –
不是这行: 'XmlNode xSingleNode = xDL.SelectSingleNode( “// itemb”);'不是总是返回第一个itemb元素? –