XML DOM-Element-Objekt

Document 对象代表整个 XML 文档。

XML 文档对象

Document 对象是一棵 XML 文档树的根,它为我们提供了访问文档数据的主要入口。

由于元素节点、文本节点、注释、处理指令等不能存在于文档之外,因此 Document 对象还包含创建这些对象的方法。Node 对象有一个 ownerDocument 属性,该属性将它们与创建它们的 Document 关联起来。

Document 对象的属性

Eigenschaft Beschreibung
childNodes 返回文档的子节点的 NodeList。
doctype 返回与文档关联的文档类型声明。
documentElement 返回文档的根节点。
documentURI 设置或返回文档的位置。
domConfig 返回调用 normalizeDocument() 时使用的配置。
firstChild 返回文档的第一个子节点。
implementation 返回处理此文档的 DOMImplementation 对象。
inputEncoding 返回文档使用的编码方式(在解析时)。
lastChild Return the last child of the document.
nodeName Return the name of the node (depending on its type).
nodeType Return the node type of the node.
nodeValue Set or return the value of the node (depending on its type).
xmlEncoding Return the XML encoding of the document.
xmlStandalone Set or return whether the document is standalone.
xmlVersion Set or return the XML version of the document.

Methods of the Document object

Methode Beschreibung
adoptNode() Adopt a node from another document into this document, and return the adopted node.
createAttribute() Create an attribute node with the specified name, and return a new Attr object.
createAttributeNS() Create an attribute node with the specified name and namespace, and return a new Attr object.
createCDATASection() Create a CDATA section node.
createComment() Create a comment node.
createDocumentFragment() Create an empty DocumentFragment object and return it.
createElement() Create an element node.
createElementNS() Create an element node with the specified namespace.
createEntityReference() Create an EntityReference object and return this object.
createProcessingInstruction() Create a ProcessingInstruction object and return this object.
createTextNode() Create a text node.
getElementById() Return the element with the given id attribute value.
getElementsByTagName() Return a NodeList of all elements with the specified name.
getElementsByTagNameNS() Return a NodeList of all elements with the specified name and namespace.
importNode() Import a node from another document to this document.
normalizeDocument()
renameNode() Rename an element node or an attribute node.

Properties of the DocumentType object

Every document has a DOCTYPE attribute, which is either null or a DocumentType object.

Das DocumentType-Objekt bietet die Schnittstelle für die von XML-Dokumenten definierten Entitäten.

Eigenschaft Beschreibung
name Rückgabe des Namens der DTD.
publicId Rückgabe des Public-Identifikators der DTD.
systemId Rückgabe des Systemidentifikators der externen DTD.

Methoden des DocumentImplementation-Objekts

Das DOMImplementation-Objekt führt Operationen durch, die unabhängig vom Dokumentobjektmodell für jede spezifische Instanz sind.

Methode Beschreibung
createDocument() Erstellen eines neuen DOM Document-Objekts mit der angegebenen Dokumenttyp.
createDocumentType() Erstellen eines leeren DocumentType-Knotens.
getFeature() Rückgabe des Objekts der API, die die angegebene Eigenschaft und Version implementiert (falls vorhanden).
hasFeature() Überprüfen Sie, ob das DOM-Implementierung die spezifischen Eigenschaften und Versionen implementiert hat.

Eigenschaften des ProcessingInstruction-Objekts

Das ProcessingInstruction-Objekt stellt eine Verarbeitungsinstruktion dar.

Eine Verarbeitungsinstruktion wird als Methode verwendet, um Prozessorspezifische Informationen im XML-Dokumentstext zu speichern.

Eigenschaft Beschreibung
data Setzen oder Rückgabe des Inhalts der Verarbeitungsinstruktion.
target Rückkehr zum Ziel der Verarbeitungsinstruktion.