- XML code
<?xml version="1.0" standalone="yes"?><users> <xs:schema id="users" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="users" msdata:IsDataSet="true" msdata:Locale="en-US"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="user"><!--这里是表名--> <xs:complexType> <xs:sequence> <xs:element name="userName" type="xs:string" minOccurs="0" msdata:Ordinal="0" /> <xs:element name="userPass" type="xs:string" minOccurs="0" msdata:Ordinal="1" /> </xs:sequence> <xs:attribute name="id" type="xs:int" /> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema></users>
比如上面这个怎么获取<xs:element name="user"> 下的三个name值 ID UserName UserPass到一个数组
------解决方案--------------------------------------------------------
http://download.csdn.net/download/qiujialongjjj/4640825 C#基类,收藏下吧。 你能用到的
------解决方案--------------------------------------------------------
这种格式的xml没碰到过,不过我采用变通的办法,也可以解决:
- C# code
string s = File.ReadAllText(Server.MapPath("~/test.xml")); string xmlStr = s.Replace("xs:", ""); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlStr); XmlNodeList names = xmlDoc.SelectNodes(@"//element[@name='user']//*/@name"); foreach (XmlNode name in names) Response.Write(name.Value + "<br/>");
------解决方案--------------------------------------------------------
- C# code
XmlDocument xDoc = new XmlDocument(); xDoc.Load("..\\..\\test2.xml"); XmlNamespaceManager xnm = new XmlNamespaceManager(xDoc.NameTable); xnm.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); XmlNodeList xNodes = xDoc.DocumentElement.SelectNodes("//*/xs:choice/xs:element/*//*[@name]", xnm); foreach (XmlNode item in xNodes) { Console.WriteLine(item.Attributes["name"].Value); } //输出: //userName //userPass //id