当前位置: 首页 > 网络学院 > XML相关教程 > XML DOM > DOM Document
The Document object represents the entire XML document.
Document[文档]对象代表了整个XML文档。
The Document object is the root of a document tree, and gives us the primary access to the document's data.
Document[文档]对象是文档树的“根元素”,我们主要是通过它来访问文档数据的。
Since element nodes, text nodes, comments, processing instructions, etc. cannot exist outside the document, the Document object also contains methods to create these objects. The Node objects have a ownerDocument property which associates them with the Document where they were created.
因为元素节点、文本节点、注释、处理指令等均无法存在于文档元素之外,document对象同样提供了创建这些对象的方法。Node对象提供了一个ownerDocument属性,此属性可把它们与在其中创建它们的文档元素关联起来。
IE: Internet Explorer, F: Firefox, O: Opera, W3C: World Wide Web Consortium (Internet Standard)
IE: Internet Explorer, F: Firefox, O: Opera, W3C: 万维网联盟 (因特网标准)
Property 属性 | Description 描述 | IE | F | O | W3C |
---|---|---|---|---|---|
async | Specifies whether downloading of an XML file should be handled asynchronously or not 指定XML文件的下载是否与XML的处理异步进行 | 5 | 1.5 | 9 | No |
childNodes | Returns a NodeList of child nodes for the document 返回文档中的子节点列表 | 5 | 1 | 9 | Yes |
doctype | Returns the Document Type Declaration associated with the document 返回与文档相关联的文档类型声明 | 6 | 1 | 9 | Yes |
documentElement | Returns the root node of the document 返回文档中的根节点 | 5 | 1 | 9 | Yes |
documentURI | Sets or returns the location of the document 设置或返回文档的位置 | No | 1 | 9 | Yes |
domConfig | Returns the configuration used when normalizeDocument() is invoked 返回当调用normalizeDocument()时使用的配置 | No | Yes | ||
firstChild | Returns the first child node of the document 返回文档中的第一个子节点 | 5 | 1 | 9 | Yes |
implementation | Returns the DOMImplementation object that handles this document 返回处理该文档的DOMImplementation对象 | No | 1 | 9 | Yes |
inputEncoding | Returns the encoding used for the document (when parsing) 返回用于解析文档的编码 | No | 1 | No | Yes |
lastChild | Returns the last child node of the document 返回文档的最后一个子节点 | 5 | 1 | 9 | Yes |
nodeName | Returns the name of a node (depending on its type) 根据类型返回节点名称 | 5 | 1 | 9 | Yes |
nodeType | Returns the node type of a node 返回节点类型 | 5 | 1 | 9 | Yes |
nodeValue | Sets or returns the value of a node (depending on its type) 根据类型 设置或返回节点值 | 5 | 1 | 9 | Yes |
strictErrorChecking | Sets or returns whether error-checking is enforced or not 设置或返回是否需要强制进行错误检查 | No | 1 | No | Yes |
text | Returns the text of a node and its descendants. IE-only property 返回一个节点及其子节点的文本内容。仅IE支持该属性 | 5 | No | No | No |
xml | Returns the XML of a node and its descendants. IE-only property 返回一个节点及其子节点的XML内容。仅IE支持该属性 | 5 | No | No | No |
xmlEncoding | Returns the XML encoding of the document 返回文档的XML编码 | No | 1 | No | Yes |
xmlStandalone | Sets or returns whether the document is standalone 设置或返回该文档是否独立的 | No | 1 | No | Yes |
xmlVersion | Sets or returns the XML version of the document | No | 1 | No | Yes |
Method 方法 | Description 描述 | IE | F | O | W3C |
---|---|---|---|---|---|
adoptNode(sourcenode) | Adopts a node from another document to this document, and returns the adopted node 将另一个文档中的节点应用于当前文档中,并返回这个被应用的节点 | No | Yes | ||
createAttribute(name) | Creates an attribute node with the specified name, and returns the new Attr object 根据指定的名称创建属性节点,并返回全新的attr[属性]对象 | 6 | 1 | 9 | Yes |
createAttributeNS(uri,name) | Creates an attribute node with the specified name and namespace, and returns the new Attr object 根据指定的名称或命名空间创建一个属性节点,并返回全新的attr[属性]对象 | 9 | Yes | ||
createCDATASection() | Creates a CDATA section node 创建一个CDATA片断节点 | 5 | 1 | 9 | Yes |
createComment() | Creates a comment node 创建一个注释节点 | 6 | 1 | 9 | Yes |
createDocumentFragment() | Creates an empty DocumentFragment object, and returns it 创建一个空的DocumentFragment[文档片断]对象并返回它 | 5 | 1 | 9 | Yes |
createElement() | Creates an element node 创建一个元素节点 | 5 | 1 | 9 | Yes |
createElementNS() | Creates an element node with a specified namespace 通过指定的命名空间创建一个元素节点 | No | 1 | 9 | Yes |
createEntityReference(name) | Creates an EntityReference object, and returns it 创建一个EntityReference[实体参数]对象并返回它 | 5 | No | Yes | |
createProcessingInstruction(target,data) | Creates a ProcessingInstruction object, and returns it 创建一个ProcessingInstruction[处理指令]对象并返回它 | 5 | 9 | Yes | |
createTextNode() | Creates a text node 创建一个文本节点 | 5 | 1 | 9 | Yes |
getElementById(id) | Returns the element that has an ID attribute with the given value. If no such element exists, it returns null 返回与指定的ID相对应的元素值。如果该元素不存在,则返回空值 | 5 | 1 | 9 | Yes |
getElementsByTagName() | Returns a NodeList of all elements with a specified name 通过指定的名称返回所有元素的NodeList [节点列表] | 5 | 1 | 9 | Yes |
getElementsByTagNameNS() | Returns a NodeList of all elements with a specified name and namespace 通过指定的名称和命名空间返回所有元素的NodeList [节点列表] | No | 1 | 9 | Yes |
importNode(nodetoimport,deep) | Imports a node from another document to this document. This method creates a new copy of the source node. If the deep parameter is set to true, it imports all children of the specified node. If set to false, it imports only the node itself. This method returns the imported node 从另一个文档把某个节点导入此文档。此方法可创建源节点的一个新的副本。如果deep参数被设置为true,那么会导入指定节点的所有子节点。如果被设置为false,那么仅会导入节点本身。此方法会返回被导入的节点。 | 9 | Yes | ||
normalizeDocument() | No | Yes | |||
renameNode() | Renames an element or attribute node 重命名一个元素或属性节点 | No | Yes |