• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

DOM节点中属性nodeName、nodeType和nodeValue的区别Delphi

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

http://msdn.microsoft.com/zh-cn/library/vstudio/hf9hbf87.aspx

 

<?xml version="1.0"?>
  <books>
    <book>
        <author>Carson</author>
        <price format="dollar">31.95</price>
        <pubdate>05/01/2001</pubdate>
    </book>
    <pubinfo>
        <publisher>MSPress</publisher>
        <state>WA</state>
    </pubinfo>
  </books> 

 

 

 

XmlDocument 类(扩展XmlNode)支持用于对整个文档执行操作(例如,将文档加载到内存中或将 XML 保存到文件中)的方法。

 XmlNode 和 XmlDocument 都具有性能和可用性增强,并通过方法和属性执行下列操作:

  • 访问和修改 DOM 特定的节点,如元素节点、实体引用节点等。

  • 除检索节点包含的信息(如元素节点中的文本)外,还检索整个节点。

其中的某些特性包括:

  • 唯一没有父级的节点是文档根,因为它是顶级节点,包含了文档本身和文档片段。

  • 以下是可以有子节点的节点类型列表。

    • Document

    • DocumentFragment

    • EntityReference

    • Element

    • Attribute

    XmlDeclarationNotationEntityCDATASectionTextCommentProcessingInstruction 和 DocumentType 节点没有子节点。

  • 处于同一级别、在关系图中由 book 和 pubinfo 节点表示的节点是同级。

属性被视为元素节点的属性,由名称和值对组成。

dollar

有关更多信息,请参见访问 DOM 中的属性。

 

 

http://linder0209.iteye.com/blog/1458823

http://www.css88.com/archives/5017

 

 

(一)nodeName 属性含有某个节点的名称。

 

元素节点的 nodeName 是标签名称

属性节点的 nodeName 是属性名称

文本节点的 nodeName 永远是 #text

文档节点的 nodeName 永远是 #document

注释:nodeName 所包含的 XML 元素的标签名称永远是 大写 的

 

nodeName 属性含有某个节点的名称。

  • 元素(element)节点的 nodeName 是标签名称
  • 属性(attribute)节点的 nodeName 是属性名称
  • 文本(text)节点的 nodeName 永远是 #text
  • 文档(document)节点的 nodeName 永远是 #document

 

(二)nodeValue

对于文本节点,nodeValue 属性包含文本。

对于属性节点,nodeValue 属性包含属性值。

nodeValue 属性对于文档节点 <document> 和元素节点 <element> 是不可用的。

 

(三)nodeType

nodeType 属性可返回节点的类型。

最重要的节点类型是:

元素类型 节点类型

元素element 1

属性attr 2

文本text 3

注释comments   8

文档document   9

 

http://www.w3schools.com/dom/dom_nodetype.asp

Node Types

The following table lists the different W3C node types, and which node types they may have as children:

Node type Description Children
Document Represents the entire document (the root-node of the DOM tree) Element (max. one), ProcessingInstruction, Comment, DocumentType
DocumentFragment Represents a "lightweight" Document object, which can hold a portion of a document Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
DocumentType Provides an interface to the entities defined for the document None
ProcessingInstruction Represents a processing instruction None
EntityReference Represents an entity reference Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Element Represents an element Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
Attr Represents an attribute Text, EntityReference
Text Represents textual content in an element or attribute None
CDATASection Represents a CDATA section in a document (text that will NOT be parsed by a parser) None
Comment Represents a comment None
Entity Represents an entity Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
Notation Represents a notation declared in the DTD None

Node Types - Return Values

The following table lists what the nodeName and the nodeValue properties will return for each node type:

Node type nodeName returns nodeValue returns
Document #document null
DocumentFragment #document fragment null
DocumentType doctype name null
EntityReference entity reference name null
Element element name null
Attr attribute name attribute value
ProcessingInstruction target content of node
Comment #comment comment text
Text #text content of node
CDATASection #cdata-section content of node
Entity entity name null
Notation notation name null

NodeTypes - Named Constants

NodeType Named Constant
1 ELEMENT_NODE
2 ATTRIBUTE_NODE
3 TEXT_NODE
4 CDATA_SECTION_NODE
5 ENTITY_REFERENCE_NODE
6 ENTITY_NODE
7 PROCESSING_INSTRUCTION_NODE
8 COMMENT_NODE
9 DOCUMENT_NODE
10 DOCUMENT_TYPE_NODE
11 DOCUMENT_FRAGMENT_NODE
12 NOTATION_NODE

 

 http://www.w3school.com.cn/xmldom/dom_nodes_nodelist.asp

<bookstore>
  <book category="children">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="web" cover="paperback">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
  <book category="web">
    <title lang="en">XQuery Kick Start</title>
    <author>James McGovern</author>
    <author>Per Bothner</author>
    <author>Kurt Cagle</author>
    <author>James Linn</author>
    <author>Vaidyanathan Nagarajan</author>
    <year>2003</year>
    <price>49.99</price>
  </book>
</bookstore>

下面的图像表示 "books.xml" 中 <title> 元素的节点列表:

 

Xml.XMLIntf.IXMLNode.NodeType

Indicates the type of the node.

Read NodeType to determine the type of the node. The type reflects the way the node is used in the XML document. 

TNodeType = (
    ntReserved, 
    ntElement, 
    ntAttribute, 
    ntText, 
    ntCData,
    ntEntityRef, 
    ntEntity, 
    ntProcessingInstr, 
    ntComment, 
    ntDocument,
    ntDocType, 
    ntDocFragment, 
    ntNotation);

 

Xml.XMLIntf.IXMLNode.NodeName

Indicates the node name.

NodeName is the name of the underlying DOM node.

The node's name depends on the type of the node, as indicated in the following table:

 

NodeType NodeName

ntAttribute

The attribute name

ntElement

The tag name

ntText

'#text'

ntCData

'#cdata-section'

ntEntityRef

The name of the entity reference.

ntEntity

The entity name

ntProcessingInstr

the target of the processing instruction

ntComment

'#comment'

ntDocument

'#document'

ntDocType

The document type name

ntDocFragment

'#document-fragment'

ntNotation

The notation name 

Xml.XMLIntf.IXMLNode.NodeValue

Specifies the value of this node.

Use NodeValue to get or set the value of the node. The meaning of a node's value depends on the type of the node, as indicated in the following table: 

 

NodeType Value

ntAttribute

The attribute value

ntElement

If the element contains only text, this is that text value.

Otherwise, trying to read or set NodeValue causes an exception.

ntText

The text

ntCData

The content of the CDATA section.

ntProcessingInstr

The content of the processing instruction except for the target.

ntComment

The value (text) of the comment. 

Xml.XMLIntf.IXMLNode.IsTextElement

Indicates whether the node has a single text value.

Read IsTextElement to determine whether this node represents a single text value. For example, if the node represents the following: 

 

<Title> Understanding XML </Title>

IsTextElement is true, because the node represents a tagged element and the text that is its value.

Note: 

In the underlying DOM implementation, nodes for which IsTextElement is true are element nodes that have a single child node that is a text node. 

IXMLNode flattens this out so that you can use the element node to work with the text value (through the Text property),

rather than requiring you to use a separate node for the text value.

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
DelphiTstringListStringlist的特殊用法发布时间:2022-07-18
下一篇:
收藏: Delphi版的Http隧道发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap