The DOMDocument class

(PHP 5, PHP 7, PHP 8)

Einführung

Represents an entire HTML or XML document; serves as the root of the document tree.

Klassenbeschreibung

class DOMDocument extends DOMNode implements DOMParentNode {
/* Geerbte Konstanten */
/* Eigenschaften */
public readonly ?DOMDocumentType $doctype;
public readonly ?DOMElement $documentElement;
public readonly ?string $actualEncoding;
public ?string $encoding;
public readonly ?string $xmlEncoding;
public ?string $version;
public readonly mixed $config;
public bool $recover;
public readonly ?DOMElement $firstElementChild;
public readonly ?DOMElement $lastElementChild;
public readonly int $childElementCount;
/* Geerbte Eigenschaften */
public readonly string $nodeName;
public readonly int $nodeType;
public readonly ?DOMNode $parentNode;
public readonly ?DOMElement $parentElement;
public readonly DOMNodeList $childNodes;
public readonly ?DOMNode $firstChild;
public readonly ?DOMNode $lastChild;
public readonly ?DOMNode $previousSibling;
public readonly ?DOMNode $nextSibling;
public readonly ?DOMNamedNodeMap $attributes;
public readonly bool $isConnected;
public readonly ?DOMDocument $ownerDocument;
public readonly ?string $namespaceURI;
public string $prefix;
public readonly ?string $localName;
public readonly ?string $baseURI;
/* Methoden */
public function __construct(string $version = "1.0", string $encoding = "")
public function adoptNode(DOMNode $node): DOMNode|false
public function append(DOMNode|string ...$nodes): void
public function createAttribute(string $localName): DOMAttr|false
public function createAttributeNS(?string $namespace, string $qualifiedName): DOMAttr|false
public function createComment(string $data): DOMComment
public function createElement(string $localName, string $value = ""): DOMElement|false
public function createElementNS(?string $namespace, string $qualifiedName, string $value = ""): DOMElement|false
public function createTextNode(string $data): DOMText
public function getElementById(string $elementId): ?DOMElement
public function getElementsByTagName(string $qualifiedName): DOMNodeList
public function getElementsByTagNameNS(?string $namespace, string $localName): DOMNodeList
public function importNode(DOMNode $node, bool $deep = false): DOMNode|false
public function load(string $filename, int $options = 0): bool
public function loadHTML(string $source, int $options = 0): bool
public function loadHTMLFile(string $filename, int $options = 0): bool
public function loadXML(string $source, int $options = 0): bool
public function normalizeDocument(): void
public function prepend(DOMNode|string ...$nodes): void
public function registerNodeClass(string $baseClass, ?string $extendedClass): true
public function relaxNGValidate(string $filename): bool
public function relaxNGValidateSource(string $source): bool
public function replaceChildren(DOMNode|string ...$nodes): void
public function save(string $filename, int $options = 0): int|false
public function saveHTML(?DOMNode $node = null): string|false
public function saveHTMLFile(string $filename): int|false
public function saveXML(?DOMNode $node = null, int $options = 0): string|false
public function schemaValidate(string $filename, int $flags = 0): bool
public function schemaValidateSource(string $source, int $flags = 0): bool
public function validate(): bool
public function xinclude(int $options = 0): int|false
/* Geerbte Methoden */
public function DOMNode::appendChild(DOMNode $node): DOMNode|false
public function DOMNode::C14N(
    bool $exclusive = false,
    bool $withComments = false,
    ?array $xpath = null,
    ?array $nsPrefixes = null
): string|false
public function DOMNode::C14NFile(
    string $uri,
    bool $exclusive = false,
    bool $withComments = false,
    ?array $xpath = null,
    ?array $nsPrefixes = null
): int|false
public function DOMNode::cloneNode(bool $deep = false): DOMNode|false
public function DOMNode::getLineNo(): int
public function DOMNode::getNodePath(): ?string
public function DOMNode::getRootNode(?array $options = null): DOMNode
public function DOMNode::hasAttributes(): bool
public function DOMNode::hasChildNodes(): bool
public function DOMNode::insertBefore(DOMNode $node, ?DOMNode $child = null): DOMNode|false
public function DOMNode::isDefaultNamespace(string $namespace): bool
public function DOMNode::isEqualNode(?DOMNode $otherNode): bool
public function DOMNode::isSameNode(DOMNode $otherNode): bool
public function DOMNode::isSupported(string $feature, string $version): bool
public function DOMNode::lookupNamespaceURI(?string $prefix): ?string
public function DOMNode::lookupPrefix(string $namespace): ?string
public function DOMNode::normalize(): void
public function DOMNode::removeChild(DOMNode $child): DOMNode|false
public function DOMNode::replaceChild(DOMNode $node, DOMNode $child): DOMNode|false
public function DOMNode::__sleep(): array
public function DOMNode::__wakeup(): void
}

Eigenschaften

actualEncoding

Deprecated as of PHP 8.4.0. Actual encoding of the document, is a readonly equivalent to encoding.

childElementCount

The number of child elements.

config

Deprecated as of PHP 8.4.0. Configuration used when DOMDocument::normalizeDocument() is invoked.

doctype

The Document Type Declaration associated with this document.

documentElement

The DOMElement object that is the first document element. If not found, this evaluates to null.

documentURI

The location of the document or null if undefined.

encoding

Encoding of the document, as specified by the XML declaration. This attribute is not present in the final DOM Level 3 specification, but is the only way of manipulating XML document encoding in this implementation.

firstElementChild

First child element or null.

formatOutput

Nicely formats output with indentation and extra space. This has no effect if the document was loaded with preserveWhitespace enabled.

implementation

The DOMImplementation object that handles this document.

lastElementChild

Last child element or null.

preserveWhiteSpace

Do not remove redundant white space. Default to true. Setting this to false has the same effect as passing LIBXML_NOBLANKS as option to DOMDocument::load() etc.

recover

Proprietary. Enables recovery mode, i.e. trying to parse non-well formed documents. This attribute is not part of the DOM specification and is specific to libxml.

resolveExternals

Set it to true to load external entities from a doctype declaration. This is useful for including character entities in your XML document.

standalone

Deprecated. Whether or not the document is standalone, as specified by the XML declaration, corresponds to xmlStandalone.

strictErrorChecking

Throws DOMException on errors. Default to true.

substituteEntities

Proprietary. Whether or not to substitute entities. This attribute is not part of the DOM specification and is specific to libxml. Default to false.

Achtung

Enabling entity substitution may facilitate XML External Entity (XXE) attacks.

validateOnParse

Loads and validates against the DTD. Default to false.

Achtung

Enabling validating the DTD may facilitate XML External Entity (XXE) attacks.

version

Deprecated. Version of XML, corresponds to xmlVersion.

xmlEncoding

An attribute specifying, as part of the XML declaration, the encoding of this document. This is null when unspecified or when it is not known, such as when the Document was created in memory.

xmlStandalone

An attribute specifying, as part of the XML declaration, whether this document is standalone. This is false when unspecified. A standalone document is one where there are no external markup declarations. An example of such a markup declaration is when the DTD declares an attribute with a default value.

xmlVersion

An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the "XML" feature, the value is "1.0".

Changelog

Version Beschreibung
8.4.0 actualEncoding and config are formally deprecated now.
8.0.0 DOMDocument implements DOMParentNode now.
8.0.0 The unimplemented method DOMDocument::renameNode() has been removed.

Anmerkungen

Hinweis:

Die Erweiterung DOM verwendet die UTF-8 Kodierung. Es kann mb_convert_encoding(), UConverter::transcode() oder iconv() verwendet werden, um mit anderen Zeichenkodierungen zu arbeiten.

Hinweis:

Wird json_encode() auf ein DOMDocument-Objekt angewendet, entspricht das dem Kodieren eines leeren Objekts.

Inhaltsverzeichnis