12 #include <libxml/xmlreader.h> 13 #include <libxml/xmlerror.h> 17 #include <zypp/base/LogControl.h> 18 #include <zypp/base/LogTools.h> 19 #include <zypp/base/Exception.h> 20 #include <zypp/base/String.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 <<
' ' << (
void *)buffer_r << endl;
52 std::list<std::string> structuredErrors;
53 void structuredErrorFunc(
void * userData, xmlErrorPtr error )
60 structuredErrors.push_back( err );
66 #define X(m) SEC << " " << #m << "\t" << error->m << endl 67 #define XS(m) SEC << " " << #m << "\t" << (error->m?error->m:"NA") << endl 87 struct ParseException :
public Exception
90 : Exception(
"Parse error: " + ( structuredErrors.empty() ?
std::string(
"unknown error"): structuredErrors.back() ) )
92 for_( it, structuredErrors.begin(), --structuredErrors.end() )
108 : _stream( stream_r )
109 , _reader( xmlReaderForIO( ioread, ioclose, &_stream,
110 stream_r.path().
asString().c_str(),
"utf-8", XML_PARSE_PEDANTIC ) )
118 structuredErrors.clear();
119 xmlTextReaderSetStructuredErrorHandler(
_reader, structuredErrorFunc, NULL );
162 int ret = xmlTextReaderRead(
_reader );
182 int ret = xmlTextReaderMoveToNextAttribute(
_reader );
std::string asString(const Patch::Category &obj)
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Reader(const InputStream &stream_r, const Validate &validate_r=Validate::none())
Ctor.
NodeType nodeType() const
Get the node type of the current node.
XmlString value() const
Provides the text value of the node if present.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
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 basename() const
Return the last component of this path.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool seekToNode(int depth_r, const std::string &name_r)
bool seekToEndNode(int depth_r, const std::string &name_r)
int depth() const
The depth of the node in the tree.
xmlTextReader document validation.
Base class for Exception.
XmlString nodeText()
If the current node is not empty, advances the reader to the next node, and returns the value...
XmlString name() const
The qualified name of the node, equal to Prefix :LocalName.
int isEmptyElement() const
Check if the current node is empty.
Easy-to use interface to the ZYPP dependency resolver.