c#访问xml文件中遍历指定节点名的要素

时间:2023-02-09 23:18:03

 <?xml version="1.0" ?>
- <ROWDATA>
- <ROW>
  <FQBH>01</FQBH> 
  <FQNM>河南</FQNM> 
  <VHGT>34031.600</VHGT> 
  <FQBD>113.61 34.864500,113.61 35.01,113.950316 35.108349,113.950316 34.847770,113.61 34.864500</FQBD>
  </ROW>
- <ROW>
  <FQBH>02</FQBH> 
  <FQNM>河北</FQNM> 
  <VHGT>40829.900</VHGT> 

  <FQBD>113.950316 34.847770,113.950316 35.108349,114.358615 35.185328,114.358615 34.843372,113.950316 34.847770</FQBD>
  </ROW>
  </ROWDATA> 

 

c#访问上述数据中FQBD中元素的值:代码如下 

  ArrayList pArrayList = new ArrayList();
            string path=@"D:\VisualStudio2010\Projects\coordInfo.XML";
            XmlDocument appSetting = new XmlDocument();
            appSetting.Load(path);
            XmlNode pXmlNode = appSetting.DocumentElement;            
            foreach(XmlNode p in pXmlNode)
            {                
                if (p.Name == "ROW")
                {
                    XmlNodeList pXmlNodeList=p.ChildNodes;
                    foreach(XmlNode p2 in pXmlNodeList)

                    {                    

                       if (p2.Name == "FQBD")
                        {
                            pArrayList.Add(p2.InnerText);
                        }
                    }
                }                
            }