c# 读取带有命名空间的XML

1.xml的内容








 
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
  
  
  
  
  
  
  



  XmlDocument xml = new XmlDocument();
            xml.Load("1.xml");
            XmlNamespaceManager xnm = new XmlNamespaceManager(xml.NameTable);
            xnm.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            string xpath = "//xs:sequence/xs:element";
            XmlNodeList nodes = xml.SelectNodes(xpath, xnm);
            foreach (XmlNode item in nodes)
            {
                string title = item.Attributes["name"].InnerText;
                string type = item.Attributes["type"].InnerText;
                listBox1.Items.Add(title + " " + type);

            }

你可能感兴趣的:(c#)