XML文件:
<?xml version="1.0" encoding="utf-8"?>
<XmlData> <A>
<a>True</a> </A> <B>
<b></b> </B> <C>
<c></c>
</C></XmlData>程序文件:
using System;
using System.Xml;
using System.IO;namespace ConsoleApplication3
{
/// <summary>
/// Summary description for Class2.
/// </summary>
public class Class2
{
public void Read_XML(string NodeName,string RootNodeName, string Ret_value)
{
//
// TODO: Add constructor logic here
//
try
{ XmlDocument xmlDoc = new XmlDocument();
//Loading the Config File
xmlDoc.Load( "C://TEST.XML" );
XmlNodeList ndList = null;
//Update runs Successful date
ndList = xmlDoc.SelectSingleNode(RootNodeName).ChildNodes;
foreach ( XmlNode node in ndList)
{
XmlElement xe=(XmlElement)node;
if(xe.Name==NodeName)
{
Ret_value=xe.InnerText;
}
}
Console.WriteLine(Ret_value);
}
catch(System.Exception e )
{
throw (e);
}
}
}
}当rootNodeName =A nodename=a 时,返回Ret_value值,为什么总是出错呀??
<?xml version="1.0" encoding="utf-8"?>
<XmlData> <A>
<a>True</a> </A> <B>
<b></b> </B> <C>
<c></c>
</C></XmlData>程序文件:
using System;
using System.Xml;
using System.IO;namespace ConsoleApplication3
{
/// <summary>
/// Summary description for Class2.
/// </summary>
public class Class2
{
public void Read_XML(string NodeName,string RootNodeName, string Ret_value)
{
//
// TODO: Add constructor logic here
//
try
{ XmlDocument xmlDoc = new XmlDocument();
//Loading the Config File
xmlDoc.Load( "C://TEST.XML" );
XmlNodeList ndList = null;
//Update runs Successful date
ndList = xmlDoc.SelectSingleNode(RootNodeName).ChildNodes;
foreach ( XmlNode node in ndList)
{
XmlElement xe=(XmlElement)node;
if(xe.Name==NodeName)
{
Ret_value=xe.InnerText;
}
}
Console.WriteLine(Ret_value);
}
catch(System.Exception e )
{
throw (e);
}
}
}
}当rootNodeName =A nodename=a 时,返回Ret_value值,为什么总是出错呀??
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货