XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(strXml);
name = xmldoc.SelectSingleNode("node1/Name").InnerText;

解决方案 »

  1.   

    给个原来的test程序
    using System;
    using System.IO;
    using System.Xml;
    using System.Text;
    public class ReadXmlFileArea
    {
        private const string document = "View1.xml";    public static void Main()
        {
            ReadXmlFileArea myReadXmlFileArea = new ReadXmlFileArea();
            myReadXmlFileArea.Run(document);
        }    public void Run(String args)
        { 
          XmlTextWriter writer1 = null;
          XmlTextWriter writer2 = null;
          
          writer1 = new XmlTextWriter("polygon.xml", null);
          writer2 = new XmlTextWriter("text.xml", null);
         
          XmlTextReader reader = null;
          string sid=null;
          string myid=null;
          string myidc=null;
          string lastid=null;
          string conmouseover=null;
          string tx=null;
          string ty= null;
          string td=null;
          
          int i; 
           try
            {   
                
                // 用 XmlTextReader 加载文件
                Console.WriteLine ("正在读取文件 {0} ...", args);
                reader = new XmlTextReader (args);
                reader.WhitespaceHandling = WhitespaceHandling.None;
                Console.WriteLine ("已成功读取文件 {0} ...", args);            // 从 XmlTextReader 创建 XmlDocument
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load (reader);
                Console.WriteLine ("已成功与 XML 数据一起加载 XmlDocument ...");
                // 处理所提供的 XML 文件
                Console.WriteLine ("正在处理 ...");
                
                
                XmlNodeList nodeList=xmlDoc.SelectSingleNode("g").ChildNodes;
                
                writer1.WriteStartElement("g");
                writer2.WriteStartElement("g");
                
                foreach(XmlNode xn in nodeList)//遍历所有子节点
                  {
                    XmlElement xe=(XmlElement)xn;//将子节点类型转换为XmlElement类型
                    XmlNodeList nls=xe.ChildNodes;//继续获取xe子节点的所有子节点
                     foreach(XmlNode xn1 in nls)//遍历
                       {
                            XmlElement xe2=(XmlElement)xn1;//转换类型
                            sid=xe2.GetAttribute("id");
                            myid=sid.Substring(0,4);
                            i=sid.IndexOf('_');
                            myidc=sid.Substring(i);
                            lastid=myid+"_graph_"+myidc;
                            string tlastid=myid+"_text_"+myidc;
                            xe2.SetAttribute("id",lastid);//处理id属性完毕
                            
                            conmouseover=xe2.GetAttribute("onmouseover");
                            int j=conmouseover.IndexOf(',');
                            string d1=conmouseover.Substring(j+7);//获取区名称及以后的字符串
                            int j1=d1.IndexOf(')');
                            string tjieming=d1.Substring(0,j1-1);//获取区名称
                            
                            tx=xe2.GetAttribute("x");
                            ty=xe2.GetAttribute("y");
                            td=xe2.GetAttribute("d");
                            
                            writer1.Formatting = Formatting.Indented;
                            writer1.WriteStartElement("polygon");
                            writer1.WriteAttributeString("id", lastid);
                            writer1.WriteAttributeString("points", td);
                            writer1.WriteEndElement(); 
                            writer1.Flush();//写入polygon.xml文件完成
                            
                            
                            writer2.Formatting = Formatting.Indented;
                            writer2.WriteStartElement("text");
                            writer2.WriteAttributeString("id", tlastid);
                            writer2.WriteAttributeString("x", tx);
                            writer2.WriteAttributeString("y", ty);
                            writer2.WriteString(tjieming);
                            writer2.WriteEndElement(); 
                            writer2.Flush();//写入text.xml完成
                            
                                     }
                  }
                  
                writer1.WriteEndElement();
                writer1.Close();
                writer2.WriteEndElement();
                writer2.Close();
                }        catch (Exception e)
            {
                Console.WriteLine ("异常:{0}", e.ToString());
            }        finally
            {
                Console.WriteLine();
               
                // 通过 XmlTextReader 完成
                if (reader != null)
                    reader.Close();
            }
        }
    } // 结束类