XmlNode和XmlElement有什么区别?

ericazhoo 2003-10-18 11:30:40
请各位大侠给小弟分析一下,先谢了。
...全文
129 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
123456754321 2003-10-18
  • 打赏
  • 举报
回复
up
saucer 2003-10-18
  • 打赏
  • 举报
回复
1. you probably mean
XmlNode a = root.SelectSingleNode("(/bookstore/book/title)[position()=2]");

2. Value property is not meaningful for an element node in .NET, use InnerXml or InnerText property instead

if (a != null)
Response.Write(a.InnerText);
kuangsha007 2003-10-18
  • 打赏
  • 举报
回复
XmlNode
W3C 文档对象模型 (DOM) 级别 1 核心和核心 DOM 级别 2。DOM 是 XML 文档的内存中(缓存)树状表示形式。XmlNode 是 DOM 的 .NET 实现中的基类。它支持 XPath 选择并提供编辑功能。XmlDocument 类扩展 XmlNode,并代表 XML 文档。可使用 XmlDocument 加载和保存 XML 数据。它还含有用于创建节点的方法。
XmlElement
元素为“W3C 文档对象模型”(DOM) 中最常用的节点之一。元素可以具有与之关联的属性。XmlElement 类具有许多用于访问属性的方法(GetAttribute、SetAttribute、RemoveAttribute、GetAttributeNode 等)。也可使用 Attributes 属性,它会返回一个 XmlAttributeCollection,使您能够按名称或索引访问集合中的属性。

ericazhoo 2003-10-18
  • 打赏
  • 举报
回复
那请问
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("./")+"booksort.xml");
XmlElement root = doc.DocumentElement;
XmlNode a = root.SelectSingleNode("/bookstore/book/title[position()=2]");
Response.Write(a.Value);
上面这段代码为什么得不到预期结果?

booksort.xml
<bookstore>
<book genre="novel" publicationdate="1997" ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" ISBN="1-861001-57-6">
<title>Emma</title>
<price>19.95</price>
</book>
</bookstore>
saucer 2003-10-18
  • 打赏
  • 举报
回复
there are about 20 types of nodes in Xml, an element is one of them. In .NET, the classes represent these nodes are derived from XmlNode class, and XmlElement represents element nodes (duh! :-))

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧