PHP Class FluentDOM\Document

Inheritance: extends DOMDocument, implements FluentDOM\Node\ParentNode, use trait FluentDOM\Node\ParentNode\Properties, use trait Node\QuerySelector\Implementation, use trait FluentDOM\Node\Xpath
Show file Open project: fluentdom/fluentdom Class Usage Examples

Public Methods

Method Description
__construct ( string $version = '1.0', string $encoding = 'UTF-8' )
appendElement ( string $name, string $content = '', array $attributes = NULL ) : Element Overload appendElement to add a text content and attributes directly.
createAttribute ( string $name, string | null $value = NULL ) : DOMAttr If here is a ':' in the attribute name, consider it a namespace prefix registered on the document.
createElement ( string $name, string | array $content = NULL, array $attributes = NULL ) : Element If here is a ':' in the element name, consider it a namespace prefix registered on the document.
createElementNS ( string $namespaceURI, string $qualifiedName, string | null $content = null ) : Element
find ( string $expression ) : Query Put the document node into a FluentDOM\Query and call find() on it.
getElementsByTagName ( string $name ) : DOMNodeList Allow getElementsByTagName to use the defined namespaces.
getNamespace ( string $prefix ) : string Get the namespace for a given prefix
namespaces ( array $namespaces = NULL ) : array Get set the namespaces registered for the document object.
registerNamespace ( string $prefix, string $namespace ) register a namespace prefix for the document, it will be used in createElement and setAttribute
saveHTML ( DOMNode | DOMNodeList | null $context = NULL ) : string Allow to save HTML fragments, providing a node list
toHtml ( DOMNode | DOMNodeList | null $context = NULL ) : string Allow to save HTML fragments, providing a node list.
toXml ( DOMNode | DOMNodeList | null $context = NULL, integer $options ) : string Allow to save XML fragments, providing a node list
xpath ( ) : Xpath Generate an xpath instance for the document, if the document of the xpath instance does not match the document, regenerate it.

Private Methods

Method Description
appendAttributes ( DOMElement $node, string | array | null $content = NULL, array $attributes = NULL )
appendContent ( DOMElement $node, string | array | null $content = NULL )
validatePrefix ( string $prefix ) : string

Method Details

__construct() public method

public __construct ( string $version = '1.0', string $encoding = 'UTF-8' )
$version string
$encoding string

appendElement() public method

Overload appendElement to add a text content and attributes directly.
public appendElement ( string $name, string $content = '', array $attributes = NULL ) : Element
$name string
$content string
$attributes array
return Element

createAttribute() public method

Allow to add a attribute value directly.
public createAttribute ( string $name, string | null $value = NULL ) : DOMAttr
$name string
$value string | null
return DOMAttr

createElement() public method

Allow to add a text content and attributes directly. If $content is an array, the $content argument will be merged with the $attributes argument.
public createElement ( string $name, string | array $content = NULL, array $attributes = NULL ) : Element
$name string
$content string | array
$attributes array
return Element

createElementNS() public method

public createElementNS ( string $namespaceURI, string $qualifiedName, string | null $content = null ) : Element
$namespaceURI string
$qualifiedName string
$content string | null
return Element

find() public method

Put the document node into a FluentDOM\Query and call find() on it.
public find ( string $expression ) : Query
$expression string
return Query

getElementsByTagName() public method

Allow getElementsByTagName to use the defined namespaces.
public getElementsByTagName ( string $name ) : DOMNodeList
$name string
return DOMNodeList

getNamespace() public method

Get the namespace for a given prefix
public getNamespace ( string $prefix ) : string
$prefix string
return string

namespaces() public method

If the argument is provided ALL namespaces will be replaced.
public namespaces ( array $namespaces = NULL ) : array
$namespaces array
return array

registerNamespace() public method

register a namespace prefix for the document, it will be used in createElement and setAttribute
public registerNamespace ( string $prefix, string $namespace )
$prefix string
$namespace string

saveHTML() public method

Allow to save HTML fragments, providing a node list
public saveHTML ( DOMNode | DOMNodeList | null $context = NULL ) : string
$context DOMNode | DOMNodeList | null
return string

toHtml() public method

This is an alias for the extended saveHTML() method. Make it consistent with toXml()
public toHtml ( DOMNode | DOMNodeList | null $context = NULL ) : string
$context DOMNode | DOMNodeList | null
return string

toXml() public method

Overloading saveXML() with a removed type hint triggers an E_STRICT error, so we the function needs a new name. :-(
public toXml ( DOMNode | DOMNodeList | null $context = NULL, integer $options ) : string
$context DOMNode | DOMNodeList | null
$options integer
return string

xpath() public method

Generate an xpath instance for the document, if the document of the xpath instance does not match the document, regenerate it.
public xpath ( ) : Xpath
return Xpath