12#include <libxml/xmlreader.h>
13#include <libxml/xmlerror.h>
37 int ioread(
void * context_r,
char * buffer_r,
int bufferLen_r )
39 if ( context_r && buffer_r )
41 return reinterpret_cast<InputStream *
>(context_r)
42 ->stream().read( buffer_r, bufferLen_r ).gcount();
44 INT <<
"XML parser error: null pointer check failed " << context_r << ' ' << static_cast<void *>(buffer_r) << endl;
52 std::list<std::string> structuredErrors;
53#if LIBXML_VERSION >= 21200
54 void structuredErrorFunc(
void * userData,
const xmlError * error )
56 void structuredErrorFunc(
void * userData, xmlError * error )
64 structuredErrors.push_back( err );
69 struct ParseException :
public Exception
72 : Exception(
"Parse error: " + ( structuredErrors.
empty() ?
std::string(
"unknown error"): structuredErrors.back() ) )
74 for_( it, structuredErrors.begin(), --structuredErrors.end() )
91 , _reader( xmlReaderForIO( ioread, ioclose, &_stream,
92 stream_r.path().asString().c_str(), "utf-8", XML_PARSE_PEDANTIC ) )
95 MIL <<
"Start Parsing " << _stream << endl;
96 if ( ! _reader || ! stream_r.stream().good() )
100 structuredErrors.clear();
101 xmlTextReaderSetStructuredErrorHandler( _reader, structuredErrorFunc, NULL );
117 xmlFreeTextReader( _reader );
119 MIL <<
"Done Parsing " << _stream << endl;
124 if ( ! _node.isEmptyElement() )
128 if ( _node.nodeType() == XML_READER_TYPE_TEXT )
130 return _node.value();
144 int ret = xmlTextReaderRead( _reader );
149 xmlTextReaderClose( _reader );
164 int ret = xmlTextReaderMoveToNextAttribute( _reader );
185 xmlTextReaderClose( _reader );
198 if ( _node.depth() == depth_r
199 && _node.name() == name_r
200 && _node.nodeType() == XML_READER_TYPE_ELEMENT )
204 }
while( nextNode() );
219 if ( _node.depth() == depth_r
220 && _node.name() == name_r
221 && ( _node.nodeType() == XML_READER_TYPE_END_ELEMENT
222 || ( _node.nodeType() == XML_READER_TYPE_ELEMENT
223 && _node.isEmptyElement() ) ) )
227 }
while( nextNode() );
Base class for Exception.
std::string basename() const
Return the last component of this path.
xmlTextReader based interface to iterate xml streams.
bool seekToEndNode(int depth_r, const std::string &name_r)
XmlString nodeText()
If the current node is not empty, advances the reader to the next node, and returns the value.
bool seekToNode(int depth_r, const std::string &name_r)
bool empty() const
Whether neither idents nor provides are set.
std::string stripSuffix(const C_Str &str_r, const C_Str &suffix_r)
Strip a suffix_r from str_r and return the resulting string.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
xmlTextReader document validation.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.