我有這段代碼,我在互聯網上發現了這個。獲取所有的XML子名
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"<price>19.95</price>" +
"</book>");
XmlNode root = doc.FirstChild;
//Display the contents of the child nodes.
if (root.HasChildNodes)
{
for (int i = 0; i < root.ChildNodes.Count; i++)
{
//inner text contains the value of the childnode
Console.WriteLine(root.ChildNodes[i].Name);
}
}
它的工作,但是當我從磁盤加載XML
文件時,它不會給輸出。爲什麼?
string xmlText = File.ReadAllText("Filename");
doc.LoadXml(xmlText);
有人可以向我解釋downvote的原因嗎? – knowme