4.34. Xml::XmlNode Class

The XmlNode class provides information about the components of an XML document. This class currently cannot be constructed manually, but rather can only be returned by the XmlDoc class. It is possible that future versions of Qore will remove this restriction.

Table 4.739. XmlNode Class Method Overview

Method

Except?

Description

XmlNode::constructor()

Y

Cannot be called manually; throws an exception.

XmlNode::destructor()

N

Destroys the XmlNode object.

XmlNode::copy()

N

Creates an independent copy of the XmlNode object.

XmlNode::childElementCount() returns int

N

Returns the number of child elements of the XmlNode.

XmlNode::getSpacePreserve() returns int

N

Returns the space-preserving behavior of the XmlNode object.

XmlNode::getElementType() returns int

N

Returns the type of the XmlNode object; for possible values see XML Element Type Constants.

XmlNode::getElementTypeName() returns any

N

Returns the name of the type of the XmlNode object if possible, NOTHING if not; for possible values see the ElementTypeMap constant.

XmlNode::firstElementChild() returns any

N

Returns an XmlNode object for the first child of the current XmlNode object that is an XML element, or NOTHING if there is none.

XmlNode::getLastChild() returns any

N

Returns an XmlNode object for the last child of the current XmlNode object, or NOTHING if there is none.

XmlNode::lastElementChild() returns any

N

Returns an XmlNode object for the last child of the current XmlNode object that is an XML element, or NOTHING if there is none.

XmlNode::nextElementSibling() returns any

N

Returns an XmlNode object for the next element at the same level of the current XmlNode object, or NOTHING if there is none.

XmlNode::previousElementSibling() returns any

N

Returns an XmlNode object for the previous element at the same level of the current XmlNode object, or NOTHING if there is none.

XmlNode::getPath() returns string

Y

Returns a string representing a structured path for the current node.

XmlNode::getNsProp(string $prop, string $ns) returns any

Y

Returns the value of the given property anchored in the given namespace as a string, or NOTHING if no such property exists in the current XmlNode.

XmlNode::getProp(string $prop) returns any

Y

Returns the value of the given property as a string, or NOTHING if no such property exists in the current XmlNode.

XmlNode::getContent() returns any

N

Returns a string of the content of the current node or NOTHING if no content is available.

XmlNode::getName() returns any

N

Returns the name of the current node or NOTHING if no name is available.

XmlNode::getLang() returns any

N

Returns the language of the current node, determined by the value of the xml:lang attribute of this node or of the nearest ancestor. If no such property is available, then NOTHING is returned.

XmlNode::isText() returns bool

N

Returns True if the node is a text node, False if not.

XmlNode::isBlank() returns bool

N

Returns True if the node is empty or whitespace only, False if not.

XmlNode::getXML() returns any

N

Returns XML corresponding to the current node and all its children or NOTHING if no data is available.


4.34.1. XmlNode::constructor()

Synopsis

Cannot be called manually; throws an exception.

Table 4.740. Exceptions thrown by XmlNode::constructor()

err

desc

XMLNODE-CONSTRUCTOR-ERROR

XmlNode objects cannot be constructed manually


4.34.2. XmlNode::destructor()

Synopsis

Destroys the XmlNode object.

Example
delete $xmlnode;

4.34.3. XmlNode::copy()

Synopsis

Creates an independent copy of the XmlNode object.

Example
my XmlNode $value = $xmlnode.copy();

4.34.4. XmlNode::childElementCount()

Synopsis

Returns the number of child elements of the XmlNode.

Prototype

XmlNode::childElementCount() returns int

Example
$value = $xmlnode.childElementCount();

Table 4.741. Return Values for XmlNode::childElementCount()

Return Type

Description

int

the number of child elements of the XmlNode


4.34.5. XmlNode::getSpacePreserve()

Synopsis

Returns the space-preserving behavior of the XmlNode object.

Prototype

XmlNode::getSpacePreserve() returns int

Example
$value = $xmlnode.getSpacePreserve();

Table 4.742. Return Values for XmlNode::getSpacePreserve()

Return Type

Description

int

The space-preserving behavior of the XmlNode: -1 = xml:space is not inherited, 0 = default, 1 = preserve


4.34.6. XmlNode::getElementType()

Synopsis

Returns the type of the XmlNode object; for possible values see XML Element Type Constants.

Prototype

XmlNode::getElementType() returns int

Example
$value = $xmlnode.getElementType();

Table 4.743. Return Values for XmlNode::getElementType()

Return Type

Description

int

the type of the XmlNode object; for possible values see XML Element Type Constants


4.34.7. XmlNode::getElementTypeName()

Synopsis

Returns the name of the type of the XmlNode object; for possible values see the ElementTypeMap constant.

Prototype

XmlNode::getElementTypeName() returns any

Example
$value = $xmlnode.getElementTypeName();

Table 4.744. Return Values for XmlNode::getElementTypeName()

Return Type

Description

string

the name of the type of the XmlNode object; for possible values see the ElementTypeMap constant


4.34.8. XmlNode::firstElementChild()

Synopsis

Returns an XmlNode object for the first child of the current XmlNode object that is an XML element, or NOTHING if there is none.

Prototype

XmlNode::firstElementChild() returns any

Example
$value = $xmlnode.firstElementChild();

Table 4.745. Return Values for XmlNode::firstElementChild()

Return Type

Description

XmlNode or nothing

returns an XmlNode object for the first element child of the current XmlNode object, or NOTHING if there is none


4.34.9. XmlNode::getLastChild()

Synopsis

Returns an XmlNode object for the last child of the current XmlNode object, or NOTHING if there is none.

Prototype

XmlNode::getLastChild() returns any

Example
$value = $xmlnode.getLastChild();

Table 4.746. Return Values for XmlNode::getLastChild()

Return Type

Description

XmlNode or nothing

returns an XmlNode object for the last child of the current XmlNode object, or NOTHING if there is none


4.34.10. XmlNode::lastElementChild()

Synopsis

Returns an XmlNode object for the last child of the current XmlNode object that is an XML element, or NOTHING if there is none.

Prototype

XmlNode::lastElementChild() returns any

Example
$value = $xmlnode.lastElementChild();

Table 4.747. Return Values for XmlNode::lastElementChild()

Return Type

Description

XmlNode or nothing

returns an XmlNode object for the last element child of the current XmlNode object, or NOTHING if there is none


4.34.11. XmlNode::nextElementSibling()

Synopsis

Returns an XmlNode object for the next element at the same level of the current XmlNode object, or NOTHING if there is none.

Prototype

XmlNode::nextElementSibling() returns any

Example
$value = $xmlnode.nextElementSibling();

Table 4.748. Return Values for XmlNode::nextElementSibling()

Return Type

Description

XmlNode or nothing

returns an XmlNode object for the next element sibling of the current XmlNode object, or NOTHING if there is none


4.34.12. XmlNode::previousElementSibling()

Synopsis

Returns an XmlNode object for the previous element at the same level of the current XmlNode object, or NOTHING if there is none.

Prototype

XmlNode::previousElementSibling() returns any

Example
$value = $xmlnode.previousElementSibling();

Table 4.749. Return Values for XmlNode::previousElementSibling()

Return Type

Description

XmlNode or nothing

returns an XmlNode object for the previous element sibling of the current XmlNode object, or NOTHING if there is none


4.34.13. XmlNode::getPath()

Synopsis

Returns a string representing a structured path for the current node.

Prototype

XmlNode::getPath() returns string

Example
$value = $xmlnode.getPath();

Table 4.750. Return Values for XmlNode::getPath()

Return Type

Description

string

a string representing a structured path for the current node


4.34.14. XmlNode::getNsProp()

Synopsis

Returns the value of the given property anchored in the given namespace, or NOTHING if no such property exists in the current XmlNode.

Prototype

XmlNode::getNsProp(string $prop, string $ns) returns any

Example
$value = $xmlnode.getNsProp($prop, $namespace);

Table 4.751. Arguments for XmlNode::getNsProp()

Argument

Description

string $prop

The name of the property to retrieve

string $ns

The name of the namespace of the property


Table 4.752. Return Values for XmlNode::getNsProp()

Return Type

Description

string or nothing

the value of the property or NOTHING if it does not exist


Table 4.753. Exceptions thrown by XmlNode::getNsProp()

err

desc

XMLNODE-GETNSPROP-ERROR

missing or invalid argument


4.34.15. XmlNode::getProp()

Synopsis

Returns the value of the given property, or NOTHING if no such property exists in the current XmlNode.

Prototype

XmlNode::getProp(string $prop) returns any

Example
$value = $xmlnode.getProp($prop);

Table 4.754. Arguments for XmlNode::getProp()

Argument

Description

string $prop

The name of the property to retrieve


Table 4.755. Return Values for XmlNode::getProp()

Return Type

Description

string or nothing

the value of the property or NOTHING if it does not exist


Table 4.756. Exceptions thrown by XmlNode::getProp()

err

desc

XMLNODE-GETPROP-ERROR

missing or invalid argument


4.34.16. XmlNode::getContent()

Synopsis

Returns a string of the content of the current node or NOTHING if there is none.

Prototype

XmlNode::getContent() returns any

Example
$value = $xmlnode.getContent();

Table 4.757. Return Values for XmlNode::getContent()

Return Type

Description

string or nothing

a string of the content of the current node or NOTHING if there is no content


4.34.17. XmlNode::getName()

Synopsis

Returns the name of the current node or NOTHING if no name is available.

Prototype

XmlNode::getName() returns any

Example
$value = $xmlnode.getName();

Table 4.758. Return Values for XmlNode::getName()

Return Type

Description

string or nothing

the name of the current node or NOTHING if no name is available


4.34.18. XmlNode::getLang()

Synopsis

Returns the language of the current node, determined by the value of the xml:lang attribute of this node or of the nearest ancestor. If no such property is available, then NOTHING is returned.

Prototype

XmlNode::getLang() returns any

Example
$value = $xmlnode.getLang();

Table 4.759. Return Values for XmlNode::getLang()

Return Type

Description

string or nothing

the language of the current node, determined by the value of the xml:lang attribute of this node or of the nearest ancestor. If no such property is available, then NOTHING is returned.


4.34.19. XmlNode::isText()

Synopsis

Returns True if the node is a text node, False if not.

Prototype

XmlNode::isText() returns bool

Example
$value = $xmlnode.isText();

Table 4.760. Return Values for XmlNode::isText()

Return Type

Description

bool

True if the node is a text node, False if not


4.34.20. XmlNode::isBlank()

Synopsis

Returns True if the node is empty or whitespace only, False if not.

Prototype

XmlNode::isBlank() returns bool

Example
$value = $xmlnode.isBlank();

Table 4.761. Return Values for XmlNode::isBlank()

Return Type

Description

bool

True if the node is empty or whitespace only, False if not


4.34.21. XmlNode::getXML()

Synopsis

Returns a string containing XML corresponding to the current node and all its children or NOTHING if no information is available.

Prototype

XmlNode::getXML() returns any

Example
$value = $xmlnode.getXML();

Table 4.762. Return Values for XmlNode::getXML()

Return Type

Description

string or nothing

XML corresponding to the current node and all its children or NOTHING if no information is available