Methods of objects in Dom

Source: Internet
Author: User
Tags processing instruction

From: http://www.cnblogs.com/dujun0618/articles/688061.html

1. absolutechildnumber

Meaning: return the sequence number of the node relative to all its brothers (regardless of whether the name is the same)

Syntax: absolutechildnumber (node)

Parameter: node-object. The node number to be returned.

Example:

1. Assume that the document structure is: <document>

<XSL: eval>

Absolutechildnumber (this. selectnodes ("/document/body"). Item (0 ))

</XSL: eval>

2. Determine the serial number of the current node relative to all its brothers.

<XSL: eval> absolutechildnumber (this) </XSL: eval>

2. ancestorchildnumber

Meaning: return the sequence number of the nearest ancestor Node Based on the given ancestor node name (relative to the Same Name node ). If no ancestor is found, 0 is returned.

Syntax: ancestorchildnumber (bstrnodename, pnode)

Parameters:

Bstrnodename ── string. Name of the searched ancestor node.

Pnode-object. Search for the Start Node.

Example:

Find the closest report ancestor node to the current node.

Ancestorchildnumber ("Report", this)

Iii. Attributes

Meaning: return the set of node attributes.

Syntax: object. Attributes

Parameter: Object-Node object

Example:

Number of current node attributes

This. Attributes. Length

Value of the third attribute of the current node

This. attributs. Item (2). Value

Or this. Attributes. Item (2). Text

Or this. attributes (2). Text

Note: If the given subscript is greater than the sum of attributes minus 1, an error occurs. The subscript of the first attribute is 0.

Iv. basename

Meaning: returns the basic name with namespace restrictions, that is, excluding the name prefix.

Syntax: object. basename

Parameter: Object-Node object

Example: Basic name of the current node: This. basename

V. childnumber

Meaning: return the serial number of the node relative to the same name compatriot

Syntax: childnumber (object)

Parameter: Object? Leng Yun? /P>

Example: assume that the XML document structure is as follows:

<X> <Y> <z/> <Y/> </x>

If the current node is Z, childnumber (this) returns 1, while absolutechildnumber (this) returns 3.

6. datatype

Description: sets or reads the Data Type of a node.

Syntax: Set the Data Type of the Node object. datatype = objvalue

Data Type of the read node objvalue = object. datatype

Parameter: Object-Node object

Example: Read the Data Type of the current node

Dttype = This. datatype

VII. Depth

Meaning: Specify the depth of the node that appears on the document tree, that is, the node is located at the layer of the document, and the top node is located

At the first layer, the root node (that is, the node represented by "/") is located at Layer 0th.

Syntax: depth (pnode)

Parameter: pnode-Node object

Example: depth of the current node

Depth (this)

8. firstchild and lastchild

Meaning: return the first subnode (or the last subnode) of the node ).

Syntax: pnode. firstchild

Pnode. lastchild

Parameter: pnode-Node object

Example: name of the first node of the current node

This. firstchild. nodename

9. formatindex

Meaning: format the provided integer with the specified counting system.

Syntax: formatindex (lindex, bstrformat)

Parameters:

Lindex ── integer value or variable

Bstrformat-data format. Optional values include a, a, I, I, 1, and 01 (in the form of a value with 0 headers, it is useful if Fixed Length numbers such as 0001 and 0002 are required)

Example: upper-case roman numerals of the current node

Formatindex (childnumber (this), "I ")

10. formatnumber

Meaning: outputs a value in a specified format.

Syntax: formatnumber (dblnumber, bstrformat)

Parameter: The description is the same as formatnumber. The difference is that the format can be decimal.

Example: format the value of variable A as two decimal formatnumber (a, "#. 00 ")

11. haschildnodes

Meaning: If a node has a subnode, true (-1) is returned; otherwise, false (0) is returned)

Syntax: pnode. haschildnodes ()

Note: Unlike the previously described function, this function must contain an empty parenthesis.

Example: determine whether the current node has a subnode

This. haschildnodes

12. namespaceuri and prefix

Meaning: return the Global Resource Identifier (or prefix) of the node namespace)

Syntax: pnode. namespaceuri

Pnode. prifix

13. nextsibling, previussibling, and parentnode

Meaning: return the next brother of the node (or the parent node of the previous brother or node)

Syntax: pnode. nextsibling

Pnode. previussibling

Pnode. parentnode

Note: Applying the parentnode Method to the root node (I .e. "/"), applying the previoussibling Method to the first child node, and applying the nextsibling Method to the last child node will cause errors, you can use this relational operator = (equal to) and! = (Not equal to) to determine whether a node is a specified node, in the format of pnode1 = pnode2 or pnode2! = Pnode2.

14. nodename

Meaning: return an element, attribute, entry name, or a specific string of other types of nodes.

Syntax: pnode. nodename

Example: name of the current node

This. nodename

15th, nodetype, nodetypestring

Meaning: return the numeric form (or string form) of the node type)

Syntax: pnode. nodetype or pnode. nodetypestring

Return Value:

Node Type
Node Type Number node type string
 
Element
1
"Element"
 
Element attributes
2
"Attribute"
 
Markup-delimited region of Text
3
"Text"
 
Processing Instruction
7
"Processing_instruction"
 
Comment
8
"Comment"
 
Document entity
9
"Document"
 

 

Sixteen, nodetypedvalue

Meaning: return the value of a node based on the predefined Data Type of the node.

Syntax: pnode. nodetypedvalue

Example: assume that the data type of the current node is fixed.14.4. In the following example, the value of the node is returned as a numerical value instead of a text string.

This. nodetypedvalue

17. nodevalue

Meaning: return the text of the node.

Syntax: pnode. nodevalue

Note: This method is not used for element nodes. It can be used for attributes, CDATA, comments, text, and other nodes.

Example: the value of the first attribute of the current element

This. attributes (0). nodevalue

Text in the current element (assuming that the element contains only text, no other elements, that is, <mark> text </mark>, we recommend you try it several times to learn its exact usage)

This. firstchild. nodevalue

18. ownerdocument

Meaning: return the root of the document containing the node

Syntax: pnode. ownerdocument

Note: This method is used for root node errors of documents.

Nineteen, selectnodes

Meaning: The given style match is applied to the current node and the matched node set is returned.

Syntax: pnode. selectnodes ("pattern ")

Tip: The expression of pattern is similar to the value of the select attribute of <XSL: For-each>, which starts "/".

Search from the root of the document; traverse all nodes of the document starting with "//"; start "..."

Start from the parent node of the current node. If you want to search down from the current node, you cannot start with the above special characters.

Example: number of elements with the same name as the current node in its parent Element

Childnumber (this. selectnodes ("../" + this. nodename + "[end ()]"). Item (0 ))

Number of elements in the current element named "skill"

Childnumber (this. selectnodes ("skill [end ()]"). Item (0 ))

20. selectsinglenode

Meaning: similar to selectnodes, only the matching first node instead of the node set is returned.

Syntax: pnode. selectsinglenode ("pattern ")

Example: number of elements with the same name as the current node in its parent Element

Childnumber (this. selectsinglenode ("../" + this. nodename + "[end ()]")

Number of elements in the current element named "skill"

Childnumber (this. selectsinglenode ("skill [end ()]")

21. Text

Meaning: return the node and the text content in its subtree

Syntax: pnode. Text

Example: Text Content in the entire document

This. ownerdocument. Text

Text Content of the current Element and Its subtree

This. Text

22. xml

Meaning: return the XML Representation of the node and its descendants.

Syntax: pnode. xml

Example: XML content of the current document

This. ownerdocument. xml

Several other functions are not introduced and listed below for reference. If you are interested, please visit the http://msdn.microsoft.com for detailed instructions.

Formattime (vartime, bstrformat, vardestlocale)

Formatdate (vardate, bstrformat, vardestlocale)

Apendchild (newchild)

Definition

Clonenode

Insertbefore (newchild, refchild)

Parsed

Removechild (oldchild)

ReplaceChild (newchild, oldchild)

Specified

Transformnode (stylesheet)

Transformnodetoobject (stylesheet, outputobject)

Uniqueid (pnode)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.