PHP Class DiDom\Element

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

Protected Properties

Свойство Type Description
$node DOMNode; The DOM element instance.

Méthodes publiques

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

Méthodes protégées

Méthode Description
setNode ( DOMElement | DOMText | DOMComment $node ) : Element Sets current \DOMNode instance.

Method Details

__construct() public méthode

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

Dynamically access the element's attributes.
public __get ( string $name ) : string | null
$name string The attribute name
Résultat string | null

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

__isset() public méthode

Determine if an attribute exists on the element.
public __isset ( string $name ) : boolean
$name string The attribute name
Résultat boolean

__set() public méthode

Dynamically set an attribute on the element.
public __set ( string $name, mixed $value ) : Element
$name string The attribute name
$value mixed The attribute value
Résultat Element

__toString() public méthode

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

__unset() public méthode

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

appendChild() public méthode

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

attr() public méthode

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

attributes() public méthode

Returns the node attributes or null, if it is not DOMElement.
public attributes ( ) : array | null
Résultat array | null

child() public méthode

public child ( $index ) : Element | null
Résultat Element | null

children() public méthode

public children ( ) : Element[]
Résultat Element[]

cloneNode() public méthode

Clones a node.
public cloneNode ( boolean $deep = true ) : Element
$deep boolean Indicates whether to copy all descendant nodes
Résultat Element The cloned node

closest() public méthode

Returns first parent node matches passed selector.
public closest ( string $selector, boolean $strict = false ) : Element | null
$selector string
$strict boolean
Résultat Element | null

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

createBySelector() public static méthode

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

firstChild() public méthode

public firstChild ( ) : Element | null
Résultat Element | null

getAttribute() public méthode

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
Résultat string | null The value of the attribute or null if attribute does not exist

getDocument() public méthode

Returns the document associated with this node.
public getDocument ( ) : Document | null
Résultat Document | null

getLineNo() public méthode

Get line number for a node.
public getLineNo ( ) : integer
Résultat integer

getNode() public méthode

Get current \DOMNode instance.
public getNode ( ) : DOMNode
Résultat DOMNode

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

hasAttribute() public méthode

Determine if an attribute exists on the element.
public hasAttribute ( string $name ) : boolean
$name string The attribute name
Résultat boolean

html() public méthode

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

innerHtml() public méthode

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

is() public méthode

Indicates if two nodes are the same node.
public is ( Element | DOMNode $node ) : boolean
$node Element | DOMNode
Résultat boolean

isCommentNode() public méthode

Returns true if current node is comment.
public isCommentNode ( ) : boolean
Résultat boolean

isTextNode() public méthode

Returns true if current node is text.
public isTextNode ( ) : boolean
Résultat boolean

lastChild() public méthode

public lastChild ( ) : Element | null
Résultat Element | null

matches() public méthode

Checks that the node matches selector.
public matches ( string $selector, boolean $strict = false ) : boolean
$selector string CSS selector
$strict boolean
Résultat boolean

nextSibling() public méthode

public nextSibling ( ) : Element | null
Résultat Element | null

parent() public méthode

public parent ( ) : Element | Document | null
Résultat Element | Document | null

previousSibling() public méthode

public previousSibling ( ) : Element | null
Résultat Element | null

remove() public méthode

Removes child from list of children.
public remove ( ) : Element
Résultat Element the node that has been removed

removeAttribute() public méthode

Unset an attribute on the element.
public removeAttribute ( string $name ) : Element
$name string The attribute name
Résultat Element

replace() public méthode

Replaces a child.
public replace ( $newNode, boolean $clone = true ) : Element
$clone boolean Clone the node if true, otherwise move it
Résultat Element The node that has been replaced

setAttribute() public méthode

Set an attribute on the element.
public setAttribute ( string $name, string $value ) : Element
$name string The attribute name
$value string The attribute value
Résultat Element

setInnerHtml() public méthode

Sets inner HTML.
public setInnerHtml ( string $html ) : Element
$html string
Résultat Element

setNode() protected méthode

Sets current \DOMNode instance.
protected setNode ( DOMElement | DOMText | DOMComment $node ) : Element
$node DOMElement | DOMText | DOMComment
Résultat Element

setValue() public méthode

Set the value of this node.
public setValue ( string $value ) : Element
$value string The new value of the node
Résultat Element

text() public méthode

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

toDocument() public méthode

Get the DOM document with the current element.
public toDocument ( string $encoding = 'UTF-8' ) : Document
$encoding string The document encoding
Résultat Document

xml() public méthode

Dumps the node into a string using XML formatting.
public xml ( integer $options ) : string
$options integer Additional options
Résultat string The node 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

$node protected_oe property

The DOM element instance.
protected DOMNode; $node
Résultat DOMNode;