Qore xml Module 1.8.2
Loading...
Searching...
No Matches
Qore::Xml::SaxIterator Class Reference

The SaxIterator class provides a SAX iterator for XML data based on libxml2 More...

#include <QC_SaxIterator.dox.h>

Inheritance diagram for Qore::Xml::SaxIterator:
Qore::Xml::FileSaxIterator Qore::Xml::InputStreamSaxIterator

Public Member Methods

 constructor (string xml, string element_name, *hash opts)
 creates a new SaxIterator object from the XML string and element name passed More...
 
 copy ()
 Returns a copy of the current object (the copy will be reset to the beginning of the XML string) More...
 
auto getValue ()
 returns the current value or throws an INVALID-ITERATOR exception if the iterator is invalid More...
 
bool next ()
 Moves the current position to the next element in the XML string; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the first element in the XML if the XML string contains the required element. More...
 
 reset ()
 Reset the iterator instance to its initial state. More...
 
bool valid ()
 returns True if the iterator is currently pointing at a valid element, False if not More...
 

Detailed Description

The SaxIterator class provides a SAX iterator for XML data based on libxml2

Member Function Documentation

◆ constructor()

Qore::Xml::SaxIterator::constructor ( string  xml,
string  element_name,
*hash  opts 
)

creates a new SaxIterator object from the XML string and element name passed

Parameters
xmlan XML string to iterate
element_namethe name of the element to iterate through
optsthe following options are supported:
Example:
SaxIterator i(xml, "DetailRecord");
map printf("record %d: %y\n", $#, $1), i;
The SaxIterator class provides a SAX iterator for XML data based on libxml2
Definition: QC_SaxIterator.dox.h:7
Exceptions
XMLDOC-CONSTRUCTOR-ERRORerror parsing XML string
Since
xml 1.4 added support for the opts argument

◆ copy()

Qore::Xml::SaxIterator::copy ( )

Returns a copy of the current object (the copy will be reset to the beginning of the XML string)

Returns
a copy of the current object (the copy will be reset to the beginning of the XML string)
Example:
SaxIterator icopy = i.copy();
copy()
Returns a copy of the current object (the copy will be reset to the beginning of the XML string)

◆ getValue()

auto Qore::Xml::SaxIterator::getValue ( )

returns the current value or throws an INVALID-ITERATOR exception if the iterator is invalid

Returns
the current value or throws an INVALID-ITERATOR exception if the iterator is invalid
Code Flags:
RET_VALUE_ONLY
Example:
while (i.next()) {
printf("+ %y\n", i.getValue());
}
Exceptions
INVALID-ITERATORthe iterator is not pointing at a valid element
ITERATOR-THREAD-ERRORthis exception is thrown if this method is called from any thread other than the thread that created the object

◆ next()

bool Qore::Xml::SaxIterator::next ( )

Moves the current position to the next element in the XML string; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the first element in the XML if the XML string contains the required element.

This method will return True again after it returns False once if the XML string contains the target element, otherwise it will always return False. The iterator object should not be used after this method returns False

Returns
False if there are no more elements in the XML string (in which case the iterator object is invalid and should not be used); True if successful (meaning that the iterator object is valid)
Example:
while (i.next()) {
printf(" + %y\n", i.getValue());
}
Exceptions
ITERATOR-THREAD-ERRORthis exception is thrown if this method is called from any thread other than the thread that created the object

◆ reset()

Qore::Xml::SaxIterator::reset ( )

Reset the iterator instance to its initial state.

Reset the iterator instance to its initial state

Example
i.reset();
Exceptions
ITERATOR-THREAD-ERRORthis exception is thrown if this method is called from any thread other than the thread that created the object

◆ valid()

bool Qore::Xml::SaxIterator::valid ( )

returns True if the iterator is currently pointing at a valid element, False if not

Returns
True if the iterator is currently pointing at a valid element, False if not
Code Flags:
CONSTANT
Example:
if (i.valid())
printf("current value: %y\n", i.getValue());

The documentation for this class was generated from the following file: