以下列出关于Document 对象可用的方法。
1. abort
2. appendChild
3. cloneNode
4. createAttribute
5. createCDATASection
6. createComment
7. createDocumentFragment
8. createElement
9. createEntityReference
10. createNode
11. createProcessingInstruction
12. createTextNode
13. getElementsByTagName
14. hasChildNodes
15. insertBefore
16. load
17. loadXML
18. nodeFromID
19. parsed
20. removeChild
21. replaceChild
22. selectNodes
23. selectSingleNode
24. transformNode


abort 方法
-------------

abort 方法取消一个进行中的异步下载。

基本语法:

xmlDocument.abort();
说明:如果这个方法在异步下载时被呼叫,所有的解析动作会停止,而且在内存中的文件会被释放。


AppendChild 方法
------------------

加上一个节点当作指定节点最后的子节点。

基本语法:

xmlDocumentNode.appendChild(newChild);
说明:newChild 是附加子节点的地址。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_26.htm:
docObj = xmlDoc.documentElement;
alert(docObj.xml);
objNewNode = docObj.appendChild(xmlDoc.documentElement. firstChild);
alert(docObj.xml);


cloneNode 方法
---------------

建立指定节点的复制。

基本语法:

xmlDocumentNode.cloneNode(deep);
说明:deep 是一个布尔值。如果为true,此节点会复制以指定节点发展出去的所有节点。如果是false,只有指定的节点和它的属性被复制。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_27.htm:
currNode = xmlDoc.documentElement.childNodes.item(1);
objClonedNode = currNode.cloneNode(1);
alert(objClonedNode.xml);


createAttribute 方法
------------------------

建立一个指定名称的属性。

基本语法:
xmlDocument.createAttribute(name);
说明:name 是被建立属性的名称。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_28.htm:
objNewAtt = xmlDoc.createAttribute("encryption");
alert(objNewAtt.xml);


createCDATASection 方法
------------------------

建立一个包含特定数据的CDATA。

基本语法:

xmlDocument.createCDATASection(data);
说明:date 是一个字符串,且包含了被置放在CDATA 的资料。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_29.htm:
objNewCDATA = xmlDoc.createCDATASection("This is a CDATA Section");
alert(objNewCDATA.xml);


createComment 方法
-------------------

建立一个包含指定数据的批注。

基本语法:

xmlDocument.createComment(data);
说明:data 是一个字符串,且包含了被置放在批注的资料。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_30.htm:
objNewComment = xmlDoc.createComment("This is a comment");
alert(objNewComment.xml);


createDocumentFragment 方法
-----------------------------

建立一个空的文件片断对象。

基本语法:

xmlDocument.createDocumentFragment();
说明:一个新的文件片断被建立,但没有加到文件树中。要加入片断到文件树中,必须使用插入方法,例如insertBefore、replaceChild 或appendChild。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_31.htm:
objNewFragment = xmlDoc.createDocumentFragment();
alert(objNewFragment.xml);


createElement 方法
--------------------

建立一个指定名称的元素。

基本语法:

xmlDocument.createElement(tagName);
说明:tagName 是一个区分大小写的字符串来指定新元素名称。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_32.htm:
objNewElement = xmlDoc.createElement("TO");
alert(objNewElement.xml);


createEntityReference 方法
-----------------------------

建立一个参照到指定名称的实体。

基本语法:

xmlDocument.createEntityReference(name);
说明:name 是一个区分大小写的字符串,来指定新实体参照的名称。一个新的实体参照被建立,但是并没有被加到文件树中。若要将实体参照加到文件树中,必须使用一种插入方法,例如:insertBefore,replaceChild,或appendChild。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_33.htm:
objNewER = xmlDoc.createEntityReference("eRef");
alert(objNewER.xml);


createNode 方法
----------------------

建立一个指定型态、名称,及命名空间的新节点。

基本语法:

xmlDocument.createNode(type, name, nameSpaceURI);
说明:type 用来确认要被建立的节点型态,name 是一个字符串来确认新节点的名称,命名空间的前缀则是选择性的。nameSpaceURI 是一个定义命名空间URI 的字符串。如果前缀被包含在名称参数中,此节点会在nameSpaceURI 的内文中以指定的前缀建立。如果不包含前缀,指定的命名空间会被视为预设的命名空间。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_34.htm:
objNewNode = xmlDoc.createNode(1, "TO", "");
alert(objNewNode.xml);


createProcessingInstruction 方法
-----------------------------------

建立一个新的处理指令,包含了指定的目标和数据。

基本语法:

xmlDocument.createProcessingInstruction(target, data);
说明:target 是表示目标、名称或处理指令的字符串。Data 是表示处理指令的值。一个新的处理指令被建立,但是并没有加到文件树中。要把处理指令加到文件树中,必须使用插入方法,例如:insertBefore、 replaceChild,或是appendChild。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_35.htm:
objNewPI =
xmlDoc.createProcessingInstruction(‘XML’, ‘version="1.0"’);
alert(objNewPI.xml);


createTextNode 方法
------------------------

建立一个新的text 节点,并包含指定的数据。

基本语法:

xmlDocument.createTextNode(data);
-
说明:data 是一个代表新text 节点的字符串。一个新的text 节点被建立,但是没有加到文件树中。若要将节点加到文件树中,必须使用插入方法,例如:insertBefore,replaceChild或appendChild。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_36.htm:
objNewTextNode = xmlDoc.createTextNode("This is a text node.");
alert(objNewTextNode.xml);


getElementsByTagName 方法
-----------------------------

传回指定名称的元素集合。

基本语法:

objNodeList = xmlDocument.getElementsByTagName(tagname);
说明:tagname 是一个字符串,代表找到的元素卷标名称。使用tagname "*"传回文件中所有找到的元素。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_37.htm:
objNodeList = xmlDoc.getElementsByTagName("*");
alert(objNodeList.item(1).xml);


haschildnodes 方法
----------------------

如果指定的节点有一个或更多子节点,传回值为true。

基本语法:

boolValue = xmlDocumentNode.hasChildNodes() ;
说明:如果此节点有子节点传回值为true,否则传回false 值。

使用范例:

以下的范例请参照随书光盘中的AppxA\LstA_38.htm:
boolValue = xmlDoc.documentElement.hasChildNodes();
alert(boolValue);