ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# XML DOM - Document 对象 Document 对象代表整个 XML 文档。 ## Document 对象 Document 对象是文档树的根,并为我们提供对文档数据的最初(或最顶层)的访问入口。 由于元素节点、文本节点、注释、处理指令等均无法存在于文档之外,Document 对象也提供了创建这些对象的方法。Node 对象提供了一个 ownerDocument 属性,此属性可把它们与在其中创建它们的 Document 关联起来。 ## Document 对象属性 | 属性 | 描述 | | --- | --- | | [async](prop-document-async.html) | 规定 XML 文件的下载是否应当被异步处理。 | | [childNodes](prop-document-childnodes.html) | 返回文档的子节点的节点列表。 | | [doctype](dom-prop-document-doctype.html) | 返回与文档相关的文档类型声明(DTD,全称 Document Type Declaration)。 | | [documentElement](dom-prop-document-documentelement.html) | 返回文档的根节点。 | | [documentURI](dom-prop-document-documenturi.html) | 设置或返回文档的位置。 | | domConfig | 返回 normalizeDocument() 被调用时所使用的配置。 | | [firstChild](prop-document-firstchild.html) | 返回文档的第一个子节点。 | | [implementation](dom-prop-document-implementation.html) | 返回处理该文档的 DOMImplementation 对象。 | | [inputEncoding](dom-prop-document-inputencoding.html) | 返回用于文档的编码方式(在解析时)。 | | [lastChild](prop-document-lastchild.html) | 返回文档的最后一个子节点。 | | [nodeName](prop-document-nodename.html) | 返回节点的名称(根据节点的类型)。 | | [nodeType](prop-document-nodetype.html) | 返回节点的节点类型。 | | [nodeValue](prop-document-nodevalue.html) | 设置或返回节点的值(根据节点的类型)。 | | [strictErrorChecking](dom-prop-document-stricterrorchecking.html) | 设置或返回是否强制进行错误检查。 | | [xmlEncoding](prop-document-xmlencoding.html) | 返回文档的 XML 编码。 | | [xmlStandalone](prop-document-xmlstandalone.html) | 设置或返回文档是否为 standalone。 | | [xmlVersion](prop-document-xmlversion.html) | 设置或返回文档的 XML 版本。 | ## Document 对象方法 | 方法 | 描述 | | --- | --- | | adoptNode(sourcenode) | 从另一个文档向本文档选定一个节点,然后返回被选节点。 | | createAttribute(name) | 创建带有指定名称的属性节点,并返回新的 Attr 对象。 | | createAttributeNS(uri,name) | 创建带有指定名称和命名空间的属性节点,并返回新的 Attr 对象。 | | [createCDATASection()](met-document-createcdatasection.html) | 创建 CDATA 区段节点。 | | [createComment()](dom-met-document-createcomment.html) | 创建注释节点。 | | createDocumentFragment() | 创建空的 DocumentFragment 对象,并返回此对象。 | | [createElement()](dom-met-document-createelement.html) | 创建元素节点。 | | [createElementNS()](met-document-createelementns.html) | 创建带有指定命名空间的元素节点。 | | createEntityReference(name) | 创建 EntityReference 对象,并返回此对象。 | | createProcessingInstruction(target,data) | 创建一个 ProcessingInstruction 对象,并返回此对象。 | | [createTextNode()](dom-met-document-createtextnode.html) | 创建文本节点。 | | getElementById(id) | 返回带有指定值的 ID 属性的元素。如果不存在这样的元素,则返回 null。 | | [getElementsByTagName()](dom-met-document-getelementsbytagname.html) | 返回带有指定名称的所有元素的 NodeList。 | | [getElementsByTagNameNS()](met-document-getelementsbytagnamens.html) | 返回带有指定名称和命名空间的所有元素的 NodeList。 | | importNode(nodetoimport,deep) | 从另一个文档向本文档选定一个节点。该方法创建源节点的一个新的副本。如果 deep 参数设置为 true,它将导入指定节点的所有子节点。 如果设置为 false,它将只导入节点本身。该方法返回被导入的节点。 | | normalizeDocument() | | [renameNode()](dom-met-document-renamenode.html) | 重命名元素或属性节点。 |