XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("xxx.xml"));//xxx.xml是你的xml文件名,不一定需要用Server.MapPath,能找到这个文件就行;
XmlNode node;
XmlElement key = doc.DocumentElement;
node = key.SelectSingleNode("//xs:element[@name='告诉我']");
Response.Write(node.Attributes["type"].Value.Tostring());
//输出xs:string
node = key.SelectSingleNode("//xs:element[@ref='告诉我']");
Response.Write(node.Attributes["minOccurs"].Value.Tostring());
//输出 0 ;试试看!
doc.Load(Server.MapPath("xxx.xml"));//xxx.xml是你的xml文件名,不一定需要用Server.MapPath,能找到这个文件就行;
XmlNode node;
XmlElement key = doc.DocumentElement;
node = key.SelectSingleNode("//xs:element[@name='告诉我']");
Response.Write(node.Attributes["type"].Value.Tostring());
//输出xs:string
node = key.SelectSingleNode("//xs:element[@ref='告诉我']");
Response.Write(node.Attributes["minOccurs"].Value.Tostring());
//输出 0 ;试试看!
XmlElement and XmlAttributefor Schema, use
XmlSchemaElement and XmlSchemaAttribute
<configuration>
<appSettings>
<test key="123" value="abc"/>
<test key="321" value="cba"/>
</appSettings>
</configuration>XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("xxx.xml"));//xxx.xml是你的xml文件名,不一定需要用Server.MapPath,能找到这个文件就行;
XmlNode node;
XmlElement key = doc.DocumentElement;
node = key.SelectSingleNode("//test[@key='123']");
Response.Write(node.Attributes["value"].Value.Tostring());
//输出abc
node = key.SelectSingleNode("//test[@key='321']");
Response.Write(node.Attributes["value"].Value.Tostring());
//输出 cba ;
或者可以试一下用XmlNodeList取出所有的节点来。