PHP Класс DiDom\Document

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$document DOMDocument
$type string

Открытые методы

Метод Описание
__construct ( string $string = null, boolean $isFile = false, string $encoding = 'UTF-8', string $type = 'html' ) Constructor.
__invoke ( string $expression, string $type = Query::TYPE_CSS, boolean $wrapElement = true ) : Element[] | DOMElement[] Searches for an node in the DOM tree for a given XPath expression or a CSS selector.
__toString ( ) : string Convert the document to its string representation.
appendChild ( Element | DOMNode | array $nodes ) : Document Add new child at the end of the children.
count ( string $expression, string $type = Query::TYPE_CSS ) : integer Counts nodes for a given XPath expression or a CSS selector.
create ( string $string = null, boolean $isFile = false, string $encoding = 'UTF-8', string $type = 'html' ) : Document Create new document.
createElement ( string $name, string $value = null, array $attributes = [] ) : Element Create new element node.
createElementBySelector ( string $selector, string $value = null, array $attributes = [] ) : Element Create new element node by CSS selector.
find ( string $expression, string $type = Query::TYPE_CSS, boolean $wrapElement = true ) : Element[] | DOMElement[] Searches for an node in the DOM tree for a given XPath expression or a CSS selector.
first ( string $expression, string $type = Query::TYPE_CSS, boolean $wrapElement = true ) : Element | DOMElement | null Searches for an node in the DOM tree and returns first element or null.
format ( boolean $format = true ) : Document Nicely formats output with indentation and extra space.
getDocument ( ) : DOMDocument
getElement ( ) : DOMElement
getType ( ) : string Returns the type of document (XML or HTML).
has ( string $expression, string $type = Query::TYPE_CSS ) : boolean Checks the existence of the node.
html ( integer $options = LIBXML_NOEMPTYTAG ) : string Dumps the internal document into a string using HTML formatting.
is ( Document | DOMDocument $document ) : boolean Indicates if two documents are the same document.
load ( string $string, boolean $isFile = false, string $type = 'html', integer $options ) Load HTML or XML.
loadHtml ( string $html, integer $options ) : Document Load HTML from a string.
loadHtmlFile ( string $filepath, integer $options ) : Document Load HTML from a file.
loadXml ( string $xml, integer $options ) : Document Load XML from a string.
loadXmlFile ( string $filepath, integer $options ) : Document Load XML from a file.
preserveWhiteSpace ( boolean $value = true ) : Document Set preserveWhiteSpace property.
text ( ) : string Get the text content of this node and its descendants.
toElement ( ) : Element
xml ( integer $options ) : string Dumps the internal document into a string using XML formatting.
xpath ( string $expression, boolean $wrapElement = true ) : Element[] | DOMElement[] Searches for an node in the DOM tree for a given XPath expression.

Защищенные методы

Метод Описание
loadFile ( string $filepath ) : strting Reads entire file into a string.
wrapNode ( $node )

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( string $string = null, boolean $isFile = false, string $encoding = 'UTF-8', string $type = 'html' )
$string string HTML or XML string or file path
$isFile boolean Indicates that in first parameter was passed to the file path
$encoding string The document encoding
$type string The document type

__invoke() публичный Метод

Searches for an node in the DOM tree for a given XPath expression or a CSS selector.
public __invoke ( string $expression, string $type = Query::TYPE_CSS, boolean $wrapElement = true ) : Element[] | DOMElement[]
$expression string XPath expression or a CSS selector
$type string The type of the expression
$wrapElement boolean Returns array of \DiDom\Element if true, otherwise array of \DOMElement
Результат Element[] | DOMElement[]

__toString() публичный Метод

Convert the document to its string representation.
public __toString ( ) : string
Результат string

appendChild() публичный Метод

Add new child at the end of the children.
public appendChild ( Element | DOMNode | array $nodes ) : Document
$nodes Element | DOMNode | array The appended child
Результат Document

count() публичный Метод

Counts nodes for a given XPath expression or a CSS selector.
public count ( string $expression, string $type = Query::TYPE_CSS ) : integer
$expression string XPath expression or CSS selector
$type string The type of the expression
Результат integer

create() публичный статический Метод

Create new document.
public static create ( string $string = null, boolean $isFile = false, string $encoding = 'UTF-8', string $type = 'html' ) : Document
$string string HTML or XML string or file path
$isFile boolean Indicates that in first parameter was passed to the file path
$encoding string The document encoding
$type string The document type
Результат Document

createElement() публичный Метод

Create new element node.
public createElement ( string $name, string $value = null, array $attributes = [] ) : Element
$name string The tag name of the element
$value string The value of the element
$attributes array The attributes of the element
Результат Element created element

createElementBySelector() публичный Метод

Create new element node by CSS selector.
public createElementBySelector ( string $selector, string $value = null, array $attributes = [] ) : Element
$selector string
$value string
$attributes array
Результат Element

find() публичный Метод

Searches for an node in the DOM tree for a given XPath expression or a CSS selector.
public find ( string $expression, string $type = Query::TYPE_CSS, boolean $wrapElement = true ) : Element[] | DOMElement[]
$expression string XPath expression or a CSS selector
$type string The type of the expression
$wrapElement boolean Returns array of \DiDom\Element if true, otherwise array of \DOMElement
Результат Element[] | DOMElement[]

first() публичный Метод

Searches for an node in the DOM tree and returns first element or null.
public first ( string $expression, string $type = Query::TYPE_CSS, boolean $wrapElement = true ) : Element | DOMElement | null
$expression string XPath expression or a CSS selector
$type string The type of the expression
$wrapElement boolean Returns \DiDom\Element if true, otherwise \DOMElement
Результат Element | DOMElement | null

format() публичный Метод

Nicely formats output with indentation and extra space.
public format ( boolean $format = true ) : Document
$format boolean Formats output if true
Результат Document

getDocument() публичный Метод

public getDocument ( ) : DOMDocument
Результат DOMDocument

getElement() публичный Метод

public getElement ( ) : DOMElement
Результат DOMElement

getType() публичный Метод

Returns the type of document (XML or HTML).
public getType ( ) : string
Результат string

has() публичный Метод

Checks the existence of the node.
public has ( string $expression, string $type = Query::TYPE_CSS ) : boolean
$expression string XPath expression or CSS selector
$type string The type of the expression
Результат boolean

html() публичный Метод

Dumps the internal document into a string using HTML formatting.
public html ( integer $options = LIBXML_NOEMPTYTAG ) : string
$options integer Additional options
Результат string The document html

is() публичный Метод

Indicates if two documents are the same document.
public is ( Document | DOMDocument $document ) : boolean
$document Document | DOMDocument The compared document
Результат boolean

load() публичный Метод

Load HTML or XML.
public load ( string $string, boolean $isFile = false, string $type = 'html', integer $options )
$string string HTML or XML string or file path
$isFile boolean Indicates that in first parameter was passed to the file path
$type string Type of document
$options integer Additional parameters

loadFile() защищенный Метод

Reads entire file into a string.
protected loadFile ( string $filepath ) : strting
$filepath string The path to the file
Результат strting

loadHtml() публичный Метод

Load HTML from a string.
public loadHtml ( string $html, integer $options ) : Document
$html string The HTML string
$options integer Additional parameters
Результат Document

loadHtmlFile() публичный Метод

Load HTML from a file.
public loadHtmlFile ( string $filepath, integer $options ) : Document
$filepath string The path to the HTML file
$options integer Additional parameters
Результат Document

loadXml() публичный Метод

Load XML from a string.
public loadXml ( string $xml, integer $options ) : Document
$xml string The XML string
$options integer Additional parameters
Результат Document

loadXmlFile() публичный Метод

Load XML from a file.
public loadXmlFile ( string $filepath, integer $options ) : Document
$filepath string The path to the XML file
$options integer Additional parameters
Результат Document

preserveWhiteSpace() публичный Метод

Set preserveWhiteSpace property.
public preserveWhiteSpace ( boolean $value = true ) : Document
$value boolean
Результат Document

text() публичный Метод

Get the text content of this node and its descendants.
public text ( ) : string
Результат string

toElement() публичный Метод

public toElement ( ) : Element
Результат Element

wrapNode() защищенный Метод

protected wrapNode ( $node )

xml() публичный Метод

Dumps the internal document into a string using XML formatting.
public xml ( integer $options ) : string
$options integer Additional options
Результат string The document xml

xpath() публичный Метод

Searches for an node in the DOM tree for a given XPath expression.
public xpath ( string $expression, boolean $wrapElement = true ) : Element[] | DOMElement[]
$expression string XPath expression
$wrapElement boolean Returns array of \DiDom\Element if true, otherwise array of \DOMElement
Результат Element[] | DOMElement[]

Описание свойств

$document защищенное свойство

protected DOMDocument $document
Результат DOMDocument

$type защищенное свойство

protected string $type
Результат string