我又来提问了 关于XML node的问题
- XML code
- <bookstore>- <book genre="autobiography" publicationdate="1991" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> - <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book>- <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"> <title>The Confidence Man</title> - <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book>- <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"> <title>The Gorgias</title> - <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore>
为什么上述<title>The Autobiography of Benjamin Franklin</title>
中title node的value值为null 而竟然HasChildNodes为true, “The Autobiography of Benjamin Franklin”是作为一个名为“#Text”的ChildNode的Value值出现的,InnerText也是“The Autobiography of Benjamin Franklin”,但是InnerXml为空的字符串“”。求解释。 我需要把一个Node下的所有递归子节点或属性的name和对应的值输出出来。
[解决办法]
<title>asdf</title>
这样的XML结构,asdf会被视为一个文本节点,所以你要访问title节点下的文本时,你需要node.FirstChild.Value这样访问才行。
[解决办法]