14 #include <libxml/xmlreader.h>
15 #include <libxml/xmlerror.h>
40 int ioread(
void * context_r,
char * buffer_r,
int bufferLen_r )
42 if ( context_r && buffer_r )
44 return reinterpret_cast<InputStream *
>(context_r)
45 ->stream().read( buffer_r, bufferLen_r ).gcount();
47 INT <<
"XML parser error: null pointer check failed " << context_r <<
' ' << (
void *)buffer_r << endl;
55 std::list<std::string> structuredErrors;
56 void structuredErrorFunc(
void * userData, xmlErrorPtr
error )
61 std::string err(
str::form(
"%s[%d] %s", Pathname::basename(error->file).c_str(), error->line,
63 structuredErrors.push_back( err );
69 #define X(m) SEC << " " << #m << "\t" << error->m << endl
70 #define XS(m) SEC << " " << #m << "\t" << (error->m?error->m:"NA") << endl
90 struct ParseException :
public Exception
93 : Exception(
"Parse error: " + ( structuredErrors.empty() ? std::string(
"unknown error"): structuredErrors.back() ) )
95 for_( it, structuredErrors.begin(), --structuredErrors.end() )
111 : _stream( stream_r )
112 , _reader( xmlReaderForIO( ioread, ioclose, &_stream,
113 stream_r.path().
asString().c_str(),
"utf-8", XML_PARSE_PEDANTIC ) )
121 structuredErrors.clear();
122 xmlTextReaderSetStructuredErrorHandler(
_reader, structuredErrorFunc, NULL );
165 int ret = xmlTextReaderRead(
_reader );
185 int ret = xmlTextReaderMoveToNextAttribute(
_reader );