The XmlReader class allows XML strings to be iterated and parsed piecewise.
Table 4.763. XmlReader Class Method Overview
|
Method |
Except? |
Description |
|---|---|---|
|
|
Y |
Creates the XmlReader object based on the XmlDoc object or XML string passed. |
|
N |
Destroys the XmlReader object. | |
|
N |
Creates an independent copy of the XmlReader object. | |
|
|
Y |
Moves the position of the current instance to the next node in the stream. |
|
|
Y |
Moves the position of the current instance to the next node in the stream, skipping any whitespace nodes. |
|
|
N |
Returns the node type of the current node; for return values, see XML Node Type Constants. |
|
|
N |
Returns a string giving the node type of the current node or NOTHING if the node type name cannot be determined; for possible return values, see the values of the NodeTypeMap constant. |
|
|
N |
Returns the depth of the node in the tree. |
|
|
N |
Returns the qualified name of the node (prefix:LocalName) or NOTHING if no name is available. |
|
|
N |
Returns the text value of the node or NOTHING if not available. |
|
|
N |
Returns |
|
|
N |
Returns |
|
|
N |
Returns |
|
|
N |
Returns |
|
|
N |
Returns |
|
|
N |
Returns |
|
|
Y |
Returns a hash corresponding to the XML string from the current node position, including all its children, or a string if the reader is on an element with no children, or NOTHING if there is no more data to read. |
|
|
Y |
Returns a hash corresponding to the XML string from the current node position, including all its children, or a string if the reader is on an element with no children, or NOTHING if there is no more data to read. |
|
|
N |
Returns the number of attributes of the current node |
|
|
N |
Returns the base URI of the node if known, NOTHING if not. |
|
|
N |
Returns the encoding string given in the XML string or NOTHING if none is given. |
|
|
N |
Returns the local name of the node or NOTHING if no name is available. |
|
|
N |
Returns the URI defining the namespace associated with the node, or NOTHING if not available. |
|
|
N |
Returns the shorthand reference to the namespace associated with the node, or NOTHING if not available. |
|
|
N |
Returns the xml:lang scope within which the node resides or NOTHING if there is none. |
|
|
N |
Returns a string giving the XML version of the source document (normally "1.0") |
|
|
Y |
Returns the value of the attribute matching the qualified name passed, or NOTHING if no such attribute exists in the current XmlReader. |
|
|
Y |
Returns the value of the given attribute anchored in the given namespace, or NOTHING if no such attribute exists in the current XmlReader. |
|
|
N |
Returns the string value of the attribute with the specified index relative to the containing element, or NOTHING if no such attribute exists in the current XmlReader. |
|
|
N |
Returns the namespace corresponding to the given prefix in the scope of the current element as a string or NOTHING if none is found. Called with no argument this function returns the default namespace. |
|
|
Y |
Moves the position of the current instance to the attribute with the specified qualified name. |
|
|
Y |
Moves the position of the current instance to the attribute with the specified local name and namespace URI. |
|
|
Y |
Moves the position of the current instance to the attribute with the specified index relative to the containing element. |
|
|
Y |
Moves the position of the current instance to the element node containing the current attribute node. |
|
|
Y |
Moves the position of the current instance to the first attribute of the current node. |
|
|
Y |
Moves the position of the current instance to the next attribute of the current node. |
|
|
Y |
Moves the position of the current instance to the next node in the tree at the same level, skipping any subtree. |
|
|
N |
Returns an XML string of the contents of the all current node's child nodes and markup, or NOTHING if the current node is neither an element nor an attribute or has no child nodes. |
|
|
N |
Returns an XML string of the contents of the current node and all child nodes and markup, or NOTHING if the current node is neither an element nor an attribute or has no child nodes. |
|
|
Y |
Set a RelaxNG schema for schema validation while parsing the XML document. This method must be called before the first call to XmlReader::read(). Not available if |
|
|
Y |
Set an XSD schema for schema validation while parsing the XML document. This method must be called before the first call to XmlReader::read(). Not available if |
Creates the XmlReader object based on the XmlDoc object or XML string passed.
XmlReader::constructor(XmlDoc $doc)
XmlReader::constructor(string $xml)
my XmlReader $xmlreader($xml);
Table 4.765. Exceptions thrown by XmlReader::constructor()
|
err |
desc |
|---|---|
|
|
invalid argument, error in XML string, etc |
Creates an independent copy of the XmlReader object.
my XmlReader $xr = $xmlreader.copy();
Moves the position of the current instance to the next node in the stream. Returns True if the read was successful, False if there are no more nodes to read. If an error occurs parsing the XML string, an exception is raised (see below).
See also XmlReader::readSkipWhitespace().
XmlReader::read() returns bool
if (!$xmlreader.read())
break;
Table 4.766. Return Values for XmlReader::read()
|
Return Type |
Description |
|---|---|
|
True if the read was successful, |
Table 4.767. Exceptions thrown by XmlReader::read()
|
err |
desc |
|---|---|
|
|
cannot move to next node due to an error parsing the XML string (exception description string contains details about the error) |
Moves the position of the current instance to the next node in the stream, skipping any whitespace nodes. Returns True if the read was successful, False if there are no more nodes to read. If an error occurs parsing the XML string, an exception is raised (see below).
See also XmlReader::read().
XmlReader::readSkipWhitespace() returns bool
if (!$xmlreader.readSkipWhitespace())
break;
Table 4.768. Return Values for XmlReader::readSkipWhitespace()
|
Return Type |
Description |
|---|---|
|
True if the read was successful, |
Table 4.769. Exceptions thrown by XmlReader::readSkipWhitespace()
|
err |
desc |
|---|---|
|
|
cannot move to next node due to an error parsing the XML string (exception description string contains details about the error) |
Returns the node type of the current node; for return values, see XML Node Type Constants.
See also NodeTypeMap.
See also XmlReader::nodeTypeName()
XmlReader::nodeType() returns int
$value = $xmlreader.nodeType();
Table 4.770. Return Values for XmlReader::nodeType()
|
Return Type |
Description |
|---|---|
|
the node type of the current node; for return values, see XML Node Type Constants |
Returns a string giving the node type of the current node or NOTHING if no current node is available; for possible return values, see the values of the NodeTypeMap constant.
See also XmlReader::nodeType()
XmlReader::nodeTypeName() returns any
$value = $xmlreader.nodeTypeName();
Table 4.771. Return Values for XmlReader::nodeTypeName()
|
Return Type |
Description |
|---|---|
|
a string giving the node type of the current node or NOTHING if no current node is available; for possible return values, see the values of the NodeTypeMap constant |
Returns the depth of the node in the tree.
XmlReader::depth() returns int
$value = $xmlreader.depth();
Table 4.772. Return Values for XmlReader::depth()
|
Return Type |
Description |
|---|---|
|
the depth of the node in the tree |
Returns the qualified name of the node (prefix:LocalName) or NOTHING if no name is available.
See also XmlReader::localName().
XmlReader::name() returns any
$value = $xmlreader.name();
Returns the text value of the node or NOTHING if not available.
XmlReader::value() returns any
$value = $xmlreader.value();
Returns True if the node has attributes or False if not.
XmlReader::hasAttributes() returns bool
$value = $xmlreader.hasAttributes();
Table 4.775. Return Values for XmlReader::hasAttributes()
|
Return Type |
Description |
|---|---|
|
True if the node has attributes, |
Returns True if the node has a text value or False if not.
XmlReader::hasValue() returns bool
$value = $xmlreader.hasValue();
Table 4.776. Return Values for XmlReader::hasValue()
|
Return Type |
Description |
|---|---|
|
True if the node has a text value, |
Returns True if an attribute node was generated from the default value defined in the DTD or schema, False if not.
XmlReader::isDefault() returns bool
$value = $xmlreader.isDefault();
Table 4.777. Return Values for XmlReader::isDefault()
|
Return Type |
Description |
|---|---|
|
True if the node an attribute node was generated from the default value defined in the DTD or schema, |
Returns True if the current node is empty or False if not.
XmlReader::isEmptyElement() returns bool
$value = $xmlreader.isEmptyElement();
Table 4.778. Return Values for XmlReader::isEmptyElement()
|
Return Type |
Description |
|---|---|
|
True if the current node is empty, |
Returns True if the current node is a namespace declaration rather than a regular attribute or False if not.
XmlReader::isNamespaceDecl() returns bool
$value = $xmlreader.isNamespaceDecl();
Table 4.779. Return Values for XmlReader::isNamespaceDecl()
|
Return Type |
Description |
|---|---|
|
True if the current node is a namespace declaration rather than a regular attribute, |
Returns True if the current reader parser context is valid, False if not
XmlReader::isValid() returns bool
$value = $xmlreader.isValid();
Table 4.780. Return Values for XmlReader::isValid()
|
Return Type |
Description |
|---|---|
|
True if the current reader parser context is valid, |
Returns Qore data corresponding to the XML starting at the current node position. If there are sub elements, a hash of the XML is returned, the sub elements representing the current node's children. If duplicate, out-of-order XML elements are found in the input string, they are deserialized to Qore hash elements with the same name as the XML element but including a caret "^" and a numeric prefix to maintain the same key order in the Qore hash as in the input XML string.
If only text is present at the current element, a string is returned. If no information is available, then NOTHING is returned.
See also XmlReader::toQoreData().
Functionally similar to parseXML()
XmlReader::toQore() returns any
$value = $xmlreader.toQore();
Table 4.781. Return Values for XmlReader::toQore()
|
Return Type |
Description |
|---|---|
Returns Qore data corresponding to the XML starting at the current node position. If there are sub elements, a hash of the XML is returned, the sub elements representing the current node's children; XML element order is maintained by appending a suffix to key names. If only text is present at the current element, a string is returned. If no information is available, then NOTHING is returned. |
Table 4.782. Exceptions thrown by XmlReader::toQore()
|
err |
desc |
|---|---|
|
|
error parsing the XML string (exception description string contains details about the error) |
Returns Qore data corresponding to the XML starting at the current node position. If there are sub elements, a hash of the XML is returned, the sub elements representing the current node's children. Note that data deserialized with this method may not be reserialized to an identical XML string due to the fact that XML elements with the same name are collapsed into Qore lists in the resulting Qore hash irrespective of the order in the original XML string.
If only text is present at the current element, a string is returned. If no information is available, then NOTHING is returned.
See also XmlReader::toQore().
Functionally similar to parseXMLAsData()
XmlReader::toQoreData() returns any
$value = $xmlreader.toQoreData();
Table 4.783. Return Values for XmlReader::toQoreData()
|
Return Type |
Description |
|---|---|
Returns Qore data corresponding to the XML starting at the current node position. If there are sub elements, a hash of the XML is returned, the sub elements representing the current node's children; does not guarantee to maintain XML element order in the hash as elements at the same level with the same name are collapsed to a Qore list. If only text is present at the current element, a string is returned. If no information is available, then NOTHING is returned. |
Table 4.784. Exceptions thrown by XmlReader::toQoreData()
|
err |
desc |
|---|---|
|
|
error parsing the XML string (exception description string contains details about the error) |
Returns the number of attributes of the current node
XmlReader::attributeCount() returns int
$value = $xmlreader.attributeCount();
Table 4.785. Return Values for XmlReader::attributeCount()
|
Return Type |
Description |
|---|---|
|
the number of attributes of the current node |
Returns the base URI of the node if known, NOTHING if not.
XmlReader::baseUri() returns any
$value = $xmlreader.baseUri();
Returns the encoding string given in the XML string or NOTHING if none is given.
XmlReader::encoding() returns any
$value = $xmlreader.encoding();
Returns the local name of the node or NOTHING if no name is available.
XmlReader::localName() returns any
$value = $xmlreader.localName();
Returns the URI defining the namespace associated with the node, or NOTHING if not available.
XmlReader::namespaceUri() returns any
$value = $xmlreader.namespaceUri();
Returns the shorthand reference to the namespace associated with the node, or NOTHING if not available.
XmlReader::prefix() returns any
$value = $xmlreader.prefix();
Returns the xml:lang scope within which the node resides or NOTHING if there is none.
XmlReader::xmlLang() returns any
$value = $xmlreader.xmlLang();
Returns a string giving the XML version of the source document (normally "1.0") or NOTHING if none is present.
XmlReader::xmlVersion() returns any
$value = $xmlreader.xmlVersion();
Returns the value of the attribute matching the qualified name passed, or NOTHING if no such attribute exists in the current XmlReader.
See also XmlReader::getAttributeNs()
XmlReader::getAttribute(string $attr) returns any
$value = $xmlreader.getAttribute($name);
Table 4.793. Arguments for XmlReader::getAttribute()
Argument | Description |
|---|---|
| The name of the attribute to retrieve |
Table 4.795. Exceptions thrown by XmlReader::getAttribute()
|
err |
desc |
|---|---|
|
|
missing or invalid argument |
Returns the value of the given attribute anchored in the given namespace, or NOTHING if no such attribute exists in the current XmlReader.
See also XmlReader::getAttribute()
XmlReader::getAttributeNs(string $attr, string $ns) returns any
$value = $xmlreader.getAttributeNs($localname, $namespaceuri);
Table 4.798. Exceptions thrown by XmlReader::getAttributeNs()
|
err |
desc |
|---|---|
|
|
missing or invalid argument |
Returns the value of the attribute with the specified index relative to the containing element, or NOTHING if no such attribute exists in the current XmlReader.
See also XmlReader::getAttribute()
XmlReader::getAttributeOffset(softint $offset = 0) returns any
$value = $xmlreader.getAttributeOffset($offset);
Table 4.799. Arguments for XmlReader::getAttributeOffset()
Argument | Description |
|---|---|
|
the index of the attribute relative to the containing element |
returns the namespace corresponding to the given prefix in the scope of the current element. If no prefix is given, the default namespace is returned.
XmlReader::lookupNamespace() returns any
XmlReader::lookupNamespace(string $ns) returns any
$value = $xmlreader.lookupNamespace($prefix);
Table 4.801. Arguments for XmlReader::lookupNamespace()
|
Argument |
Description |
|---|---|
|
The namespace prefix to resolve; if no value is sent for this argument, the default namespace is returned. |
Moves the position of the current instance to the attribute with the specified qualified name.
See also XmlReader::moveToAttributeNs()
XmlReader::moveToAttribute(string $attr) returns bool
$value = $xmlreader.moveToAttribute($name);
Table 4.803. Arguments for XmlReader::moveToAttribute()
|
Argument |
Description |
|---|---|
|
The qualified name of the attribute to move to |
Table 4.804. Return Values for XmlReader::moveToAttribute()
|
Return Type |
Description |
|---|---|
True in case of success, |
Table 4.805. Exceptions thrown by XmlReader::moveToAttribute()
|
err |
desc |
|---|---|
| missing or invalid argument |
| error parsing XML |
Moves the position of the current instance to the attribute with the specified local name and namespace URI.
See also XmlReader::moveToAttribute()
XmlReader::moveToAttributeNs(string $attr, string $ns) returns bool
$value = $xmlreader.moveToAttributeNs($localname, $namespaceuri);
Table 4.807. Return Values for XmlReader::moveToAttributeNs()
|
Return Type |
Description |
|---|---|
True in case of success, |
Table 4.808. Exceptions thrown by XmlReader::moveToAttributeNs()
|
err |
desc |
|---|---|
|
|
missing or invalid argument |
| an error occured parsing the XML string |
Moves the position of the current instance to the attribute with the specified index relative to the containing element.
See also XmlReader::moveToAttribute()
XmlReader::moveToAttributeOffset(softint $offset) returns bool
$b = $xmlreader.moveToAttributeOffset($offset);
Table 4.809. Arguments for XmlReader::moveToAttributeOffset()
Argument | Description |
|---|---|
|
the index of the attribute relative to the containing element to move to |
Table 4.810. Return Values for XmlReader::moveToAttributeOffset()
|
Return Type |
Description |
|---|---|
|
True in case of success, |
Table 4.811. Exceptions thrown by XmlReader::moveToAttributeOffset()
|
err |
desc |
|---|---|
| an error occured parsing the XML string |
Moves the position of the current instance to the element node containing the current attribute node.
XmlReader::moveToElement() returns bool
$value = $xmlreader.moveToElement();
Table 4.812. Return Values for XmlReader::moveToElement()
|
Return Type |
Description |
|---|---|
True in case of success, |
Table 4.813. Exceptions thrown by XmlReader::moveToElement()
|
err |
desc |
|---|---|
| an error occured parsing the XML string |
Moves the position of the current instance to the first attribute of the current node.
XmlReader::moveToFirstAttribute() returns bool
$value = $xmlreader.moveToFirstAttribute();
Table 4.814. Return Values for XmlReader::moveToFirstAttribute()
|
Return Type |
Description |
|---|---|
True in case of success, |
Table 4.815. Exceptions thrown by XmlReader::moveToFirstAttribute()
|
err |
desc |
|---|---|
| an error occured parsing the XML string |
Moves the position of the current instance to the next attribute of the current node.
XmlReader::moveToNextAttribute() returns bool
$value = $xmlreader.moveToNextAttribute();
Table 4.816. Return Values for XmlReader::moveToNextAttribute()
|
Return Type |
Description |
|---|---|
True in case of success, |
Table 4.817. Exceptions thrown by XmlReader::moveToNextAttribute()
|
err |
desc |
|---|---|
| an error occured parsing the XML string |
Moves the position of the current instance to the next node in the tree at the same level, skipping any subtree. Returns True if the operation succeeded, False if there are no more nodes to read. If an error occurs parsing the XML string, an exception is raised.
XmlReader::next() returns bool
$value = $xmlreader.next();
Table 4.818. Return Values for XmlReader::next()
|
Return Type |
Description |
|---|---|
True in case of success, |
Table 4.819. Exceptions thrown by XmlReader::next()
|
err |
desc |
|---|---|
| an error occured parsing the XML string |
Returns an XML string of the contents of the all current node's child nodes and markup, or NOTHING if the current node is neither an element nor an attribute or has no child nodes.
See also XmlReader::getOuterXml().
XmlReader::getInnerXml() returns any
$value = $xmlreader.getInnerXml();
Returns an XML string of the contents of the current node and all child nodes and markup, or NOTHING if the current node is neither an element nor an attribute or has no child nodes.
See also XmlReader::getInnerXml().
XmlReader::getOuterXml() returns any
$value = $xmlreader.getOuterXml();
Set a RelaxNG schema for schema validation while parsing the XML document. This method must be called before the first call to XmlReader::read()
The availability of this function depends on the presence of libxml2's xmlTextReaderRelaxNGValidate() function when Qore was compiled; for maximum portability check the constant HAVE_PARSEXMLWITHRELAXNG before calling this method. See Library Option Constants for a list of all option constants.
If any errors occur, an exception is thrown (see below).
XmlReader::relaxNGValidate(string $relaxng) returns nothing
$xmlreader.relaxNGValidate($rng);
Table 4.822. Arguments for XmlReader::relaxNGValidate()
Argument | Description |
|---|---|
| The RelaxNG schema to use to validate the XML string while parsing. |
Table 4.823. Exceptions thrown by XmlReader::relaxNGValidate()
|
err |
desc |
|---|---|
|
|
missing or invalid argument |
|
|
invalid RelaxNG schema or method called after the first call to XmlReader::read() |
| This exception is thrown when the function is not available; for maximum portability, check the constant |
Set an XSD schema for schema validation while parsing the XML document. This method must be called before the first call to XmlReader::read()
The availability of this function depends on the presence of libxml2's xmlTextReaderSchemaValidate() function when Qore was compiled; for maximum portability check the constant HAVE_PARSEXMLWITHSCHEMA before calling this method. See Library Option Constants for a list of all option constants.
If any errors occur, an exception is thrown (see below).
XmlReader::schemaValidate(string $xsd) returns nothing
$xmlreader.schemaValidate($xsd);
Table 4.824. Arguments for XmlReader::schemaValidate()
Argument | Description |
|---|---|
| The XSD schema to use to validate the XML string while parsing. |
Table 4.825. Exceptions thrown by XmlReader::schemaValidate()
|
err |
desc |
|---|---|
|
|
missing or invalid argument |
|
|
invalid RelaxNG schema or method called after the first call to XmlReader::read() |
| This exception is thrown when the function is not available; for maximum portability, check the constan
t |