請教 關于xml的問題----急。。。。。
我有一個字串,如下<Display>
<found>
<Control> lbl_Test </Control>
<Type> Lable </Type>
<Text> 程序 </Text>
</found>
<found>
<Control> txt_Test </Control>
<Type> TextBox </Type>
<Text> TextBox </Text>
</found>
</Display>
问题:根据上面的字串生成一个虚拟的XML .然后读取里面的资料,如读取 <Control> 这里面的txt_Test
請問如何操作!!!!!謝謝
开发环境是Asp.net +C#... --------------------编程问答--------------------
--------------------编程问答--------------------
XmlDocument xd = new XmlDocument();
xd.Load(@"C:\Documents and Settings\Administrator\桌面\book.xml");//此处替换为你的虚拟xml
List<string> list = new List<string>();
foreach (XmlNode node in xd.SelectNodes("//Control"))
{
list.Add(node.InnerText);
}
--------------------编程问答-------------------- System.Xml.XmlDocument document = new System.Xml.XmlDocument();
System.Xml.XmlDocument document = new System.Xml.XmlDocument();
document.InnerXml = @"<Display>
<found>
<Control> lbl_Test </Control>
<Type> Lable </Type>
<Text> 程序 </Text>
</found>
<found>
<Control> txt_Test </Control>
<Type> TextBox </Type>
<Text> TextBox </Text>
</found>
</Display>
";
System.Xml.XmlNodeList nl = document.SelectNodes(@"//Control");
foreach (System.Xml.XmlNode n in nl)
{
Console.WriteLine(n.InnerText);
}
document.LoadXml(@"<Display>
<found>
<Control> lbl_Test </Control>
<Type> Lable </Type>
<Text> 程序 </Text>
</found>
<found>
<Control> txt_Test </Control>
<Type> TextBox </Type>
<Text> TextBox </Text>
</found>
</Display>
";
System.Xml.XmlNodeList nl = document.SelectNodes(@"//Control");
foreach (System.Xml.XmlNode n in nl)
{
Console.WriteLine(n.InnerText);
} --------------------编程问答-------------------- XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("path"));
XmlNode root = doc.SelectSingleNode("Display");
XmlNodeList ele = root.SelectNodes("found/Control");
foreach (XmlNode node in ele)
{
Response.Write(node.InnerText+"<br>");
}
补充:.NET技术 , C#