DOM操作XML的数据结果存在疑惑
string xmlData = "<Class>" +" <student id=\"tcs001\">" +
" <name>AAA</name>" +
" <age>25</age>" +
" <contact>" +
" <mobile>13401012345</mobile>" +
" <telphone>010-12345678</telphone>" +
" </contact>" +
" <className>Tcs242</className>" +
" </student>" +
" <student id=\"tcs002\">" +
" <name>BBB</name>" +
" <age>23</age>" +
" <contact>" +
" <mobile>13401054321</mobile>" +
" <telphone>010-87654321</telphone>" +
" </contact>" +
" <className>Tcs242</className>" +
" </student>" +
" <student id=\"tcs003\">" +
" <name>CCC</name>" +
" <age>23</age>" +
" <contact>" +
" <mobile>134010456789</mobile>" +
" <telphone>010-9876543</telphone>" +
" </contact>" +
" <className>Tcs242</className>" +
" </student>" +
"</Class>";
myClass.LoadXml(xmlData);
XmlNodeList list = .GetElementsByTagName("*");
Program.OutputNodeNameValue(list);
static void OutputNodeNameValue(XmlNodeList list)
{
foreach (XmlNode child in list)
{
Console.WriteLine("节点名:{0},节点值:{1}", child.Name, child.Value);
Program.OutputNodeNameValue(child.ChildNodes);
}
}
为啥输出结果的结果是:
节点名:Class,节点值:
节点名:student,节点值:
节点名:name,节点值:
节点名:#text,节点值:AAA……
这个#text从哪来的呢?
XML DOM --------------------编程问答-------------------- 实际上你单步调试一下,就知道区别了。
refer : http://bbs.csdn.net/topics/390237169 --------------------编程问答-------------------- 你调试看看加载后的XML文档是怎样的结构了
补充:.NET技术 , C#