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>

解决方案 »

  1.   


            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();
            }
      

  2.   

    XmlDocument doc= new XmlDocument();
    doc.Load("");
    XmlNode no= doc.SelectSingleNode("LanguagePackage/Groups/Group[GroupName='PanSchemaClientControl']");   
    if(no!=null)
    {}
      

  3.   

    XmlNode node = root.SelectSingleNode("//Group[. ='PanSchemaClientControl']");
      

  4.   

    LanguagePackage/Groups/Group[GroupName='PanSchemaClientControl']
      

  5.   

    theGroup = (XmlElement)root.SelectSingleNode("/Groups/Group[@GroupName='PanSchemaClientControl']");没有记错的话,xpath里面,[]里面的参数前面是必须加@的你去验证一下,也只有个大概的印象了
      

  6.   

    mlDocument doc = new XmlDocument();
      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;