PHP Class DiDom\Document

Afficher le fichier Open project: imangazaliev/didom Class Usage Examples

Protected Properties

Свойство Type Description
$document DOMDocument
$type string

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
loadFile ( string $filepath ) : strting Reads entire file into a string.
wrapNode ( $node )

Method Details

__construct() public méthode

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() public méthode

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
Résultat Element[] | DOMElement[]

__toString() public méthode

Convert the document to its string representation.
public __toString ( ) : string
Résultat string

appendChild() public méthode

Add new child at the end of the children.
public appendChild ( Element | DOMNode | array $nodes ) : Document
$nodes Element | DOMNode | array The appended child
Résultat Document

count() public méthode

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
Résultat integer

create() public static méthode

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
Résultat Document

createElement() public méthode

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
Résultat Element created element

createElementBySelector() public méthode

Create new element node by CSS selector.
public createElementBySelector ( string $selector, string $value = null, array $attributes = [] ) : Element
$selector string
$value string
$attributes array
Résultat Element

find() public méthode

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
Résultat Element[] | DOMElement[]

first() public méthode

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
Résultat Element | DOMElement | null

format() public méthode

Nicely formats output with indentation and extra space.
public format ( boolean $format = true ) : Document
$format boolean Formats output if true
Résultat Document

getDocument() public méthode

public getDocument ( ) : DOMDocument
Résultat DOMDocument

getElement() public méthode

public getElement ( ) : DOMElement
Résultat DOMElement

getType() public méthode

Returns the type of document (XML or HTML).
public getType ( ) : string
Résultat string

has() public méthode

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
Résultat boolean

html() public méthode

Dumps the internal document into a string using HTML formatting.
public html ( integer $options = LIBXML_NOEMPTYTAG ) : string
$options integer Additional options
Résultat string The document html

is() public méthode

Indicates if two documents are the same document.
public is ( Document | DOMDocument $document ) : boolean
$document Document | DOMDocument The compared document
Résultat boolean

load() public méthode

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() protected méthode

Reads entire file into a string.
protected loadFile ( string $filepath ) : strting
$filepath string The path to the file
Résultat strting

loadHtml() public méthode

Load HTML from a string.
public loadHtml ( string $html, integer $options ) : Document
$html string The HTML string
$options integer Additional parameters
Résultat Document

loadHtmlFile() public méthode

Load HTML from a file.
public loadHtmlFile ( string $filepath, integer $options ) : Document
$filepath string The path to the HTML file
$options integer Additional parameters
Résultat Document

loadXml() public méthode

Load XML from a string.
public loadXml ( string $xml, integer $options ) : Document
$xml string The XML string
$options integer Additional parameters
Résultat Document

loadXmlFile() public méthode

Load XML from a file.
public loadXmlFile ( string $filepath, integer $options ) : Document
$filepath string The path to the XML file
$options integer Additional parameters
Résultat Document

preserveWhiteSpace() public méthode

Set preserveWhiteSpace property.
public preserveWhiteSpace ( boolean $value = true ) : Document
$value boolean
Résultat Document

text() public méthode

Get the text content of this node and its descendants.
public text ( ) : string
Résultat string

toElement() public méthode

public toElement ( ) : Element
Résultat Element

wrapNode() protected méthode

protected wrapNode ( $node )

xml() public méthode

Dumps the internal document into a string using XML formatting.
public xml ( integer $options ) : string
$options integer Additional options
Résultat string The document xml

xpath() public méthode

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
Résultat Element[] | DOMElement[]

Property Details

$document protected_oe property

protected DOMDocument $document
Résultat DOMDocument

$type protected_oe property

protected string $type
Résultat string