XmlDocument doc = new XmlDocument();
doc.Load("LanguagePackage.xml");
XmlElement root = null, theGroup = null, theItems = null, theItem = null;
root = doc.DocumentElement;
theGroup = (XmlElement)root.SelectSingleNode("/Groups/Group[GroupName='PanSchemaClientControl']");
得到的theGroup 总是为空,(root不为空)求帮助!下面是我的xml文件的内容
<?xml version="1.0"?>
<LanguagePackage Version="1.0">
<Groups>
<Group GroupName="PanSchemaClientControl" Description="平台客户端PanSchemaClientControl.dll的语言包">
</Group>
</Groups>
</LanguagePackage>
doc.Load("LanguagePackage.xml");
XmlElement root = null, theGroup = null, theItems = null, theItem = null;
root = doc.DocumentElement;
theGroup = (XmlElement)root.SelectSingleNode("/Groups/Group[GroupName='PanSchemaClientControl']");
得到的theGroup 总是为空,(root不为空)求帮助!下面是我的xml文件的内容
<?xml version="1.0"?>
<LanguagePackage Version="1.0">
<Groups>
<Group GroupName="PanSchemaClientControl" Description="平台客户端PanSchemaClientControl.dll的语言包">
</Group>
</Groups>
</LanguagePackage>
解决方案 »
- winfrom 小问题 大回报了
- 求助关于获取XML值的问题
- 基于SQL SERVER数据库的.NET程序发布问题?详情请进
- ADO.NET对数据集的处理有没有类似ADO的方法?
- 在windows应用程序中的dataGrid1行变化时,为什么this.BindingContext[this.dataSet11,"Customers"].Position这个东西没有变化?
- 关于用VS中自带的可视化数据集更新数据库时遇到的数据回滚问题
- webbrowser 如何执行带参数的JS函数?
- 还有人在吗?问个简单问题,怎么监视一个指定文件?
- C#中用WebClient怎么下载db或7z后缀的文件?
- 为什么我的web应用程序就是无法访问SQL数据库
- 打开excel的时候出现未指定的错误?
- 怎么获取MSWord里range的RTF格式文本?
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("XMLFile1.xml");
XmlElement root = null, theGroup = null, theItems = null, theItem = null;
root = doc.DocumentElement;
theGroup = (XmlElement)root.SelectSingleNode("Groups");
theItems = (XmlElement)theGroup.SelectSingleNode("Group"); Console.WriteLine("根节点是:"+theGroup.Name);
Console.WriteLine("次节点是:" + theItems.Name);
Console.WriteLine("次节点属性:");
foreach (XmlAttribute a in theItems.Attributes)
{
Console.WriteLine(a.InnerXml);
}
Console.ReadLine();
}
doc.Load("");
XmlNode no= doc.SelectSingleNode("LanguagePackage/Groups/Group[GroupName='PanSchemaClientControl']");
if(no!=null)
{}
doc.Load("LanguagePackage.xml");
应该用doc.LoadXml("LanguagePackage.xml") 这个方法例子:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXmlPath);
XmlNode root = xmlDoc.DocumentElement;
XmlNodeList xlName = xmlDoc.GetElementsByTagName( "Name");
if ( xlName.Count>0 )
this.m_strName = xlName[0].InnerText;