Php/docs/class.domdocument

来自菜鸟教程
跳转至:导航、​搜索

(PHP 5, PHP 7)

简介

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


类摘要


DOMDocument extends DOMNode {

/* 属性 */

public readonly string $actualEncoding

public readonly DOMConfiguration $config

public readonly DOMDocumentType $doctype

public readonly DOMElement $documentElement

public string|null $documentURI

public string $encoding

public bool $formatOutput

public readonly DOMImplementation $implementation

public bool $preserveWhiteSpace = true

public bool $recover

public bool $resolveExternals

public bool $standalone

public bool $strictErrorChecking = true

public bool $substituteEntities

public bool $validateOnParse = false

public string $version

public readonly string|null $xmlEncoding

public bool $xmlStandalone

public string $xmlVersion

/* 继承的属性 */

public readonly string $nodeName

public string $nodeValue

public readonly int $nodeType

public readonly DOMNode|null $parentNode

public readonly DOMNodeList $childNodes

public readonly DOMNode|null $firstChild

public readonly DOMNode|null $lastChild

public readonly DOMNode|null $previousSibling

public readonly DOMNode|null $nextSibling

public readonly DOMNamedNodeMap|null $attributes

public readonly DOMDocument|null $ownerDocument

public readonly string|null $namespaceURI

public string $prefix

public readonly string $localName

public readonly string|null $baseURI

public string $textContent

/* 方法 */

public __construct ([ string $version [, string $encoding ]] )

public createAttribute ( string $name ) : DOMAttr

public createAttributeNS ( string $namespaceURI , string $qualifiedName ) : DOMAttr

public createCDATASection ( string $data ) : DOMCDATASection

public createComment ( string $data ) : DOMComment

public createElement ( string $name [, string $value ] ) : DOMElement

public createElementNS ( string $namespaceURI , string $qualifiedName [, string $value ] ) : DOMElement

public createEntityReference ( string $name ) : DOMEntityReference

public createProcessingInstruction ( string $target [, string $data ] ) : DOMProcessingInstruction

public createTextNode ( string $content ) : DOMText

public getElementById ( string $elementId ) : DOMElement

public getElementsByTagName ( string $name ) : DOMNodeList

public getElementsByTagNameNS ( string $namespaceURI , string $localName ) : DOMNodeList

public importNode ( DOMNode $importedNode [, bool $deep = false ] ) : DOMNode

public load ( string $filename [, int $options = 0 ] ) : mixed

public loadHTML ( string $source [, int $options = 0 ] ) : bool

public loadHTMLFile ( string $filename [, int $options = 0 ] ) : bool

public loadXML ( string $source [, int $options = 0 ] ) : mixed

public normalizeDocument ( ) : void

public registerNodeClass ( string $baseclass , string $extendedclass ) : bool

public relaxNGValidate ( string $filename ) : bool

public relaxNGValidateSource ( string $source ) : bool

public save ( string $filename [, int $options = 0 ] ) : int

public saveHTML ([ DOMNode $node = NULL ] ) : string

public saveHTMLFile ( string $filename ) : int

public saveXML ([ DOMNode $node [, int $options = 0 ]] ) : string

public schemaValidate ( string $filename [, int $flags = 0 ] ) : bool

public schemaValidateSource ( string $source [, int $flags ] ) : bool

public validate ( ) : bool

public xinclude ([ int $options = 0 ] ) : int

/* 继承的方法 */

public DOMNode::appendChild ( DOMNode $newnode ) : DOMNode

public DOMNode::C14N ([ bool $exclusive [, bool $with_comments [, array $xpath [, array $ns_prefixes ]]]] ) : string|false

public DOMNode::C14NFile ( string $uri [, bool $exclusive = false [, bool $with_comments = false [, array $xpath [, array $ns_prefixes ]]]] ) : int|false

public DOMNode::cloneNode ([ bool $deep ] ) : DOMNode

public DOMNode::getLineNo ( ) : int

public DOMNode::getNodePath ( ) : string

public DOMNode::hasAttributes ( ) : bool

public DOMNode::hasChildNodes ( ) : bool

public DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] ) : DOMNode

public DOMNode::isDefaultNamespace ( string $namespaceURI ) : bool

public DOMNode::isSameNode ( DOMNode $node ) : bool

public DOMNode::isSupported ( string $feature , string $version ) : bool

public DOMNode::lookupNamespaceUri ( string $prefix ) : string

public DOMNode::lookupPrefix ( string $namespaceURI ) : string

public DOMNode::normalize ( ) : void

public DOMNode::removeChild ( DOMNode $oldnode ) : DOMNode

public DOMNode::replaceChild ( DOMNode $newnode , DOMNode $oldnode ) : DOMNode

}

属性

actualEncoding

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

config

Deprecated. Configuration used when DOMDocument::normalizeDocument() is invoked.

doctype

The Document Type Declaration associated with this document.

documentElement

This is a convenience attribute that allows direct access to the child node that is the document element of the document.

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.

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.

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.

Caution

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

validateOnParse

Loads and validates against the DTD. Default to false.

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.

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".


注释

Note:

此 DOM 扩展采用 UTF-8 编码。在 ISO-8859-1 编码下,使用 utf8_encode()utf8_decode() 来处理,其它编码下使用 iconv 函数处理。

Note:

When using json_encode() on a DOMDocument object the result will be that of encoding an empty object.

Table of Contents