XML DOM OBJECT

XML DOM - The Document Object

prev next

The Document object is the root-node of a document. All nodes in a node-tree are childnodes of the Document object.


Examples

We will use the following XML document in the examples below: note.xml.

documentElement - Return the node name of the root element

createElement() - Create a new element

createTextNode() - Create a new text node

createCDATASection() - Create a new CDATA node

createComment() - Create a new comment node

getElementsByTagName() - Return the value of a specified node


The Document object

The Document object represents the entire XML document.

The Document object is the root-node of a document. All nodes in a node-tree are childnodes of the Document object.

A node can be an element node, an attribute node, a text node, or any other of the node types explained in the "Node types" chapter.

IE: Internet Explorer, F: Firefox, N: Netscape, W3C: World Wide Web Consortium (Internet Standard)

Document Object Properties

PropertyDescriptionIEFNW3C
asyncSpecifies whether downloading of an XML file should be handled asynchronously or not. True means that the load() method returns the control to the caller before the download is complete. False means that the download must be completed before the caller gets the control back5--No
attributesReturns a NamedNodeMap that contains all attributes of a node516No
baseNameReturns the name of a node (without namespaces)5--No
childNodesReturns a node list that contains all children of a node516No
dataTypeReturns the data type of a node5--No
definitionReturns the definition of a node in the DTD/Schema5--No
doctypeReturns the DTD or Schema for the document616Yes
documentElementReturns the root element of the document516Yes
firstChildReturns the first child node of a node516No
implementationReturns the DOMImplementation object for this particular document616Yes
lastChildReturns the last child node of a node5--No
namespaceURIReturns the URI of the namespace516No
nextSiblingReturns the node immediately following a node. Two nodes are siblings if they have the same parent node516No
nodeNameReturns the name of the node516No
nodeTypeReturns the node type as a number516No
nodeTypedValueReturns the value of a node expressed in its defined data type5--No
nodeTypeStringReturns the node type as a string5--No
nodeValueReturns the value of the node516No
ownerDocumentReturns the Document object of a node (returns the root node of the document)516No
parentNodeReturns the parent node of a node516No
parsedReturns true if the node and all of its descendants have been parsed. Otherwise it returns false5--No
parseErrorReturns a ParseError object containing information about the parse error5--No
prefixReturns the namespace prefix of a node5--No
preserveWhiteSpaceReturns true if the default processing preserves white space. Otherwise it returns false5--No
previousSiblingReturns the node immediately previous to the current node. Two nodes are siblings if they have the same parent node516 
readyStateReturns the current state of the XML document5--No
textReturns the text content of a node and all its children5--No
urlReturns the URL for the last loaded XML document5--No
validateOnParseIndicates whether the document should be validated by the parser. Default is true. If false, only well-formed XML will be parsed5--No
xmlReturns the XML of a node and all its children5--No

Document Object Methods

MethodDescriptionIEFNW3C
abort()Aborts the XML download5--No
appendChild("name")Appends a new childnode to a node5--No
cloneNode(boolean)Creates an exact clone node of a node. If the boolean parameter is set to true, the cloned node clones all the child nodes of the original node as well5--No
createAttribute("name")Creates a new attribute node616Yes
createCDATASection("text")Creates a new CDATA section node5--Yes
createComment("text")Creates a new comment node6--Yes
createDocumentFragment()Creates an empty documentFragment object516Yes
createElement("name")Creates a new element node516Yes
createEntityReference("name")Creates a new entityReference node5--Yes
createNode(type,name,ns)Creates a new node5--No
createProcessingInstruction(target,text)Creates a new processingInstruction node5--Yes
createTextNode("text")Creates a new text node516Yes
getElementById("id") 516Yes
getElementByName("name") 516 
getElementsByTagName("name")Returns the specified node, and all its child nodes, as a node list516Yes
hasChildNodes()Returns true if a node has child nodes. Otherwise it returns false5--No
insertBefore(newnode,refnode)Inserts a new node before an existing node5--No
load("URL")Loads the specified XML document5--No
loadXML("text")Loads an XML document using the specified string5--No
nodeFromID(id)Returns the node for the element whose ID attribute matches the one specified5--No
removeChild("name")Removes and returns the specified node5--No
replaceChild(newnode,oldnode)Replaces an oldnode with a newnode, and returns the oldnode5--No
save(obj)Saves an XML document to the specified location5--No
selectNodes(pattern)Creates a node list of all the matching descendant nodes returned by the specified pattern5--No
selectSingleNode(pattern)Returns a Node object for the first descendant node to match the specified pattern5--No
transformNode(stylesheet)Processes a node and its descendants using the specified XSL stylesheet, and returns the result5--No
transformNodeToObject(stylesheet,object)Processes a node and its descendants using the specified XSL stylesheet, and returns the result in the specified object5--No

Events

EventDescriptionIEFNW3C
ondataavailableExecutes some code when the XML document data is available

Syntax: document.ondataavailable="myFunction"

5--No
onreadystatechangeExecutes some code when the readyState property changes

Syntax: document.onreadystatechange="myFunction"

5--No
ontransformnodeTriggered before each node in the XML is transformed by each node in the style sheet

Syntax: boolean = ontransformnode(nodecode,nodedata)

5--No

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值