class Document (View source)

Constants

ARRAY_SIMPLE

Use with Document::dump or Document::save method to convert document in a simple array

ARRAY_MINIMAL

Use with Document::dump or Document::save method to convert document in a minimal array

ARRAY_COMPLETE

Use with Document::dump or Document::save method to convert document in a array with all properties

HTML

Use for define format

XML

ERROR

Constants to treat errors issued by libXML as exceptions

FATAL

WARNING

Methods

__construct(int $type = 0)

Create a Document instance

static 
setSeverityLevels(int $levels)

Define libXML errors as exceptions

setLoadOptions(int $options)

Define libXML options for load a document or string

setSaveOptions(int $options)

Define libXML options for dump or save a document as file

document()

Get original document

DOMElement|null
root()

Get root element

selector()

Gets all elements that match the CSS selector

array
getNamespaces(DOMElement $element)

Get namespace attributes from root element or specific element

loadFile(string $file)

Load file

loadString(string $string)

Load string

fromArray(array $data)

Convert Array to DOM

array
toArray(int $format)

Convert DOM to Array

string|false
dump(DOMNode $node)

Convert document to XML string, HTML string or array

int|false
save(string $file)

Save document to file and returns the number of bytes written or false if an error occurred

Details

__construct(int $type = 0)

Create a Document instance

Parameters

int $type

Exceptions

Exception

static setSeverityLevels(int $levels)

Define libXML errors as exceptions

Parameters

int $levels

Exceptions

Exception

setLoadOptions(int $options)

Define libXML options for load a document or string

Parameters

int $options

setSaveOptions(int $options)

Define libXML options for dump or save a document as file

Parameters

int $options

DOMDocument document()

Get original document

Return Value

DOMDocument

DOMElement|null root()

Get root element

Return Value

DOMElement|null

Selector selector()

Gets all elements that match the CSS selector

Return Value

Selector

array getNamespaces(DOMElement $element)

Get namespace attributes from root element or specific element

Parameters

DOMElement $element

Return Value

array

loadFile(string $file)

Load file

Parameters

string $file

Exceptions

DomException

loadString(string $string)

Load string

Parameters

string $string

Exceptions

DomException

fromArray(array $data)

Convert Array to DOM

Parameters

array $data

Exceptions

Exception
DomException

array toArray(int $format)

Convert DOM to Array

Parameters

int $format

Return Value

array

string|false dump(DOMNode $node)

Convert document to XML string, HTML string or array

Parameters

DOMNode $node

Return Value

string|false

int|false save(string $file)

Save document to file and returns the number of bytes written or false if an error occurred

Parameters

string $file

Return Value

int|false