/*读取xml数据*/
/*两种xml方式*/
<aaa>
<bb>something</bb>
<cc>something</cc>
</aaa>
<aaa>
<add key="123" value="321"/>
</aaa>
/*第一种方法*/
DS.ReadXml("your xmlfile name");
Container.DataItem("bb");
Container.DataItem("cc");
DS.ReadXmlSchema("your xmlfile name");
/*第二种方法*/
<aaa>
<add key="123" value="321"/>
</aaa>
如果我要找到123然后取到321应该怎么写呢?
using System.XML;
XmlDataDocument xmlDoc = new System.Xml.XmlDataDocument();
xmlDoc.Load(@"c:\Config.xml");
XmlElement elem = xmlDoc.GetElementById("add");
string str = elem.Attributes["value"].Value
/*第三种方法*/
XmlDocument doc = new XmlDocument();
doc.Load(strXmlName);
string strBB = "";
XmlNode xnBB = doc.SelectSingleNode("/aaa/bb");
if (xnBB != null)
{
strBB = xnTitle.InnerText;
xnBB = null;
}
string strKey = "";
XmlNode xnADD = doc.SelectSingleNode("/aaa/add");
if (xnADD != null)
{
XmlNodeReader nrADD = new XmlNodeReader(xnADD);
nrADD.MoveToContent();
nrADD.MoveToAttribute("key");
strKey = nrADD.Value;
nrADD = null;
xnADD = null;
}