PHP Класс DiDom\Element

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

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

Свойство Тип Описание
$node DOMNode; The DOM element instance.

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

Метод Описание
__construct ( DOMNode | string $name, string $value = null, array $attributes = [] ) Constructor.
__get ( string $name ) : string | null Dynamically access the element's attributes.
__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.
__isset ( string $name ) : boolean Determine if an attribute exists on the element.
__set ( string $name, mixed $value ) : Element Dynamically set an attribute on the element.
__toString ( ) : string Convert the element to its string representation.
__unset ( string $name ) Unset an attribute on the model.
appendChild ( Element | DOMNode | array $nodes ) : Element Adds new child at the end of the children.
attr ( string $name, string $value = null ) : string | null | Element Alias for getAttribute and setAttribute methods.
attributes ( ) : array | null Returns the node attributes or null, if it is not DOMElement.
child ( $index ) : Element | null
children ( ) : Element[]
cloneNode ( boolean $deep = true ) : Element Clones a node.
closest ( string $selector, boolean $strict = false ) : Element | null Returns first parent node matches passed selector.
count ( string $expression, string $type = Query::TYPE_CSS ) : integer Counts nodes for a given XPath expression or a CSS selector.
create ( DOMNode | string $name, string $value = null, array $attributes = [] ) : Element Create new element.
createBySelector ( 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.
firstChild ( ) : Element | null
getAttribute ( string $name, string $default = null ) : string | null Access to the element's attributes.
getDocument ( ) : Document | null Returns the document associated with this node.
getLineNo ( ) : integer Get line number for a node.
getNode ( ) : DOMNode Get current \DOMNode instance.
has ( string $expression, string $type = Query::TYPE_CSS ) : boolean Checks the existence of the node.
hasAttribute ( string $name ) : boolean Determine if an attribute exists on the element.
html ( integer $options = LIBXML_NOEMPTYTAG ) : string Dumps the node into a string using HTML formatting.
innerHtml ( integer $options = LIBXML_NOEMPTYTAG, sting $delimiter = '' ) : string Dumps the node descendants into a string using HTML formatting.
is ( Element | DOMNode $node ) : boolean Indicates if two nodes are the same node.
isCommentNode ( ) : boolean Returns true if current node is comment.
isTextNode ( ) : boolean Returns true if current node is text.
lastChild ( ) : Element | null
matches ( string $selector, boolean $strict = false ) : boolean Checks that the node matches selector.
nextSibling ( ) : Element | null
parent ( ) : Element | Document | null
previousSibling ( ) : Element | null
remove ( ) : Element Removes child from list of children.
removeAttribute ( string $name ) : Element Unset an attribute on the element.
replace ( $newNode, boolean $clone = true ) : Element Replaces a child.
setAttribute ( string $name, string $value ) : Element Set an attribute on the element.
setInnerHtml ( string $html ) : Element Sets inner HTML.
setValue ( string $value ) : Element Set the value of this node.
text ( ) : string Get the text content of this node and its descendants.
toDocument ( string $encoding = 'UTF-8' ) : Document Get the DOM document with the current element.
xml ( integer $options ) : string Dumps the node 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.

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

Метод Описание
setNode ( DOMElement | DOMText | DOMComment $node ) : Element Sets current \DOMNode instance.

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

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

Constructor.
public __construct ( DOMNode | string $name, string $value = null, array $attributes = [] )
$name DOMNode | string The tag name of the element
$value string The value of the element
$attributes array The attributes of the element

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

Dynamically access the element's attributes.
public __get ( string $name ) : string | null
$name string The attribute name
Результат string | null

__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[]

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

Determine if an attribute exists on the element.
public __isset ( string $name ) : boolean
$name string The attribute name
Результат boolean

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

Dynamically set an attribute on the element.
public __set ( string $name, mixed $value ) : Element
$name string The attribute name
$value mixed The attribute value
Результат Element

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

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

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

Unset an attribute on the model.
public __unset ( string $name )
$name string The attribute name

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

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

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

Alias for getAttribute and setAttribute methods.
public attr ( string $name, string $value = null ) : string | null | Element
$name string The attribute name
$value string The attribute value or null if the attribute does not exist
Результат string | null | Element

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

Returns the node attributes or null, if it is not DOMElement.
public attributes ( ) : array | null
Результат array | null

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

public child ( $index ) : Element | null
Результат Element | null

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

public children ( ) : Element[]
Результат Element[]

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

Clones a node.
public cloneNode ( boolean $deep = true ) : Element
$deep boolean Indicates whether to copy all descendant nodes
Результат Element The cloned node

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

Returns first parent node matches passed selector.
public closest ( string $selector, boolean $strict = false ) : Element | null
$selector string
$strict boolean
Результат Element | null

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 element.
public static create ( DOMNode | string $name, string $value = null, array $attributes = [] ) : Element
$name DOMNode | string The tag name of the element
$value string The value of the element
$attributes array The attributes of the element
Результат Element

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

Create new element node by CSS selector.
public static createBySelector ( 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

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

public firstChild ( ) : Element | null
Результат Element | null

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

Access to the element's attributes.
public getAttribute ( string $name, string $default = null ) : string | null
$name string The attribute name
$default string The value returned if the attribute does not exist
Результат string | null The value of the attribute or null if attribute does not exist

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

Returns the document associated with this node.
public getDocument ( ) : Document | null
Результат Document | null

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

Get line number for a node.
public getLineNo ( ) : integer
Результат integer

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

Get current \DOMNode instance.
public getNode ( ) : DOMNode
Результат DOMNode

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

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

Determine if an attribute exists on the element.
public hasAttribute ( string $name ) : boolean
$name string The attribute name
Результат boolean

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

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

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

Dumps the node descendants into a string using HTML formatting.
public innerHtml ( integer $options = LIBXML_NOEMPTYTAG, sting $delimiter = '' ) : string
$options integer Additional options
$delimiter sting
Результат string

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

Indicates if two nodes are the same node.
public is ( Element | DOMNode $node ) : boolean
$node Element | DOMNode
Результат boolean

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

Returns true if current node is comment.
public isCommentNode ( ) : boolean
Результат boolean

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

Returns true if current node is text.
public isTextNode ( ) : boolean
Результат boolean

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

public lastChild ( ) : Element | null
Результат Element | null

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

Checks that the node matches selector.
public matches ( string $selector, boolean $strict = false ) : boolean
$selector string CSS selector
$strict boolean
Результат boolean

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

public nextSibling ( ) : Element | null
Результат Element | null

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

public parent ( ) : Element | Document | null
Результат Element | Document | null

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

public previousSibling ( ) : Element | null
Результат Element | null

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

Removes child from list of children.
public remove ( ) : Element
Результат Element the node that has been removed

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

Unset an attribute on the element.
public removeAttribute ( string $name ) : Element
$name string The attribute name
Результат Element

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

Replaces a child.
public replace ( $newNode, boolean $clone = true ) : Element
$clone boolean Clone the node if true, otherwise move it
Результат Element The node that has been replaced

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

Set an attribute on the element.
public setAttribute ( string $name, string $value ) : Element
$name string The attribute name
$value string The attribute value
Результат Element

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

Sets inner HTML.
public setInnerHtml ( string $html ) : Element
$html string
Результат Element

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

Sets current \DOMNode instance.
protected setNode ( DOMElement | DOMText | DOMComment $node ) : Element
$node DOMElement | DOMText | DOMComment
Результат Element

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

Set the value of this node.
public setValue ( string $value ) : Element
$value string The new value of the node
Результат Element

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

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

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

Get the DOM document with the current element.
public toDocument ( string $encoding = 'UTF-8' ) : Document
$encoding string The document encoding
Результат Document

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

Dumps the node into a string using XML formatting.
public xml ( integer $options ) : string
$options integer Additional options
Результат string The node 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[]

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

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

The DOM element instance.
protected DOMNode; $node
Результат DOMNode;