日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DOM节点中属性nodeName、nodeType和nodeValue的区别 Delphi 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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>

?

在 XML 文檔結(jié)構(gòu)中,此圖中的每個(gè)圓圈表示一個(gè)節(jié)點(diǎn)(稱為?XmlNode?對(duì)象)。?

XmlNode?對(duì)象是 DOM 樹中的基本對(duì)象。?

XmlDocument?類(擴(kuò)展XmlNode)支持用于對(duì)整個(gè)文檔執(zhí)行操作(例如,將文檔加載到內(nèi)存中或?qū)?XML 保存到文件中)的方法。

此外,XmlDocument?提供了查看和處理整個(gè) XML 文檔中的節(jié)點(diǎn)的方法。?XmlNode?和?XmlDocument?都具有性能和可用性增強(qiáng),并通過(guò)方法和屬性執(zhí)行下列操作:

  • 訪問(wèn)和修改 DOM 特定的節(jié)點(diǎn),如元素節(jié)點(diǎn)、實(shí)體引用節(jié)點(diǎn)等。

  • 除檢索節(jié)點(diǎn)包含的信息(如元素節(jié)點(diǎn)中的文本)外,還檢索整個(gè)節(jié)點(diǎn)。

Node?對(duì)象具有一組方法和屬性以及基本的和定義完善的特性。其中的某些特性包括:

  • 節(jié)點(diǎn)有單個(gè)父節(jié)點(diǎn),父節(jié)點(diǎn)是與節(jié)點(diǎn)相鄰的上一級(jí)節(jié)點(diǎn)。唯一沒有父級(jí)的節(jié)點(diǎn)是文檔根,因?yàn)樗琼敿?jí)節(jié)點(diǎn),包含了文檔本身和文檔片段。

  • 大多數(shù)節(jié)點(diǎn)可以有多個(gè)子節(jié)點(diǎn),子節(jié)點(diǎn)是與節(jié)點(diǎn)相鄰的下一級(jí)節(jié)點(diǎn)。以下是可以有子節(jié)點(diǎn)的節(jié)點(diǎn)類型列表。

    • Document

    • DocumentFragment

    • EntityReference

    • Element

    • Attribute

    XmlDeclaration、Notation、EntityCDATASection、Text、CommentProcessingInstruction?和?DocumentType?節(jié)點(diǎn)沒有子節(jié)點(diǎn)。

  • 處于同一級(jí)別、在關(guān)系圖中由?book?和?pubinfo?節(jié)點(diǎn)表示的節(jié)點(diǎn)是同級(jí)。

DOM 的一個(gè)特性是處理屬性的方式。屬性是不屬于父子關(guān)系和同級(jí)關(guān)系的節(jié)點(diǎn)。屬性被視為元素節(jié)點(diǎn)的屬性,由名稱和值對(duì)組成。

例如,如果存在由與元素price?關(guān)聯(lián)的?format="dollar" 組成的 XML 數(shù)據(jù),則單詞?format?是名稱,format?屬性的值是?dollar

為檢索?price?節(jié)點(diǎn)的?format="dollar"?屬性,可以在游標(biāo)位于?price?元素節(jié)點(diǎn)時(shí)調(diào)用?GetAttribute?方法。有關(guān)更多信息,請(qǐng)參見訪問(wèn) DOM 中的屬性。

?

?

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

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

?

?

(一)nodeName?屬性含有某個(gè)節(jié)點(diǎn)的名稱。

?

元素節(jié)點(diǎn)的?nodeName?是標(biāo)簽名稱

屬性節(jié)點(diǎn)的?nodeName?是屬性名稱

文本節(jié)點(diǎn)的?nodeName?永遠(yuǎn)是?#text

文檔節(jié)點(diǎn)的?nodeName?永遠(yuǎn)是?#document

注釋:nodeName?所包含的?XML?元素的標(biāo)簽名稱永遠(yuǎn)是 大寫 的

?

nodeName 屬性含有某個(gè)節(jié)點(diǎn)的名稱。

  • 元素(element)節(jié)點(diǎn)的 nodeName 是標(biāo)簽名稱
  • 屬性(attribute)節(jié)點(diǎn)的 nodeName 是屬性名稱
  • 文本(text)節(jié)點(diǎn)的 nodeName 永遠(yuǎn)是 #text
  • 文檔(document)節(jié)點(diǎn)的 nodeName 永遠(yuǎn)是 #document

?

(二)nodeValue

對(duì)于文本節(jié)點(diǎn),nodeValue?屬性包含文本。

對(duì)于屬性節(jié)點(diǎn),nodeValue?屬性包含屬性值。

nodeValue?屬性對(duì)于文檔節(jié)點(diǎn) <document> 和元素節(jié)點(diǎn) <element> 是不可用的。

?

(三)nodeType

nodeType?屬性可返回節(jié)點(diǎn)的類型。

最重要的節(jié)點(diǎn)類型是:

元素類型?節(jié)點(diǎn)類型

元素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 typeDescriptionChildren
DocumentRepresents the entire document (the root-node of the DOM tree)Element (max. one), ProcessingInstruction, Comment, DocumentType
DocumentFragmentRepresents a "lightweight" Document object, which can hold a portion of a documentElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
DocumentTypeProvides an interface to the entities defined for the documentNone
ProcessingInstructionRepresents a processing instructionNone
EntityReferenceRepresents an entity referenceElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
ElementRepresents an elementElement, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
AttrRepresents an attributeText, EntityReference
TextRepresents textual content in an element or attributeNone
CDATASectionRepresents a CDATA section in a document (text that will NOT be parsed by a parser)None
CommentRepresents a commentNone
EntityRepresents an entityElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
NotationRepresents a notation declared in the DTDNone

Node Types - Return Values

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

Node typenodeName returnsnodeValue returns
Document#documentnull
DocumentFragment#document fragmentnull
DocumentTypedoctype namenull
EntityReferenceentity reference namenull
Elementelement namenull
Attrattribute nameattribute value
ProcessingInstructiontargetcontent of node
Comment#commentcomment text
Text#textcontent of node
CDATASection#cdata-sectioncontent of node
Entityentity namenull
Notationnotation namenull

NodeTypes - Named Constants

NodeTypeNamed Constant
1ELEMENT_NODE
2ATTRIBUTE_NODE
3TEXT_NODE
4CDATA_SECTION_NODE
5ENTITY_REFERENCE_NODE
6ENTITY_NODE
7PROCESSING_INSTRUCTION_NODE
8COMMENT_NODE
9DOCUMENT_NODE
10DOCUMENT_TYPE_NODE
11DOCUMENT_FRAGMENT_NODE
12NOTATION_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> 元素的節(jié)點(diǎn)列表:

?

?

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:

?

NodeTypeNodeName

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:?

?

NodeTypeValue

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.

?

?

總結(jié)

以上是生活随笔為你收集整理的DOM节点中属性nodeName、nodeType和nodeValue的区别 Delphi的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。