28 #include <libxml/parser.h> 29 #include <libxml/xmlerror.h> 31 #include <boost/scope_exit.hpp> 54 static int readStream(
void *context,
char *buffer,
int len) {
59 return stream->
read(buffer, len);
79 const int options = XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS | XML_PARSE_NONET |
80 XML_PARSE_NSCLEAN | XML_PARSE_NOCDATA;
83 fileName.
c_str(), 0, options);
87 if (!parseError.
empty())
90 e.
add(
"XML document failed to parse");
94 BOOST_SCOPE_EXIT( (&xml) ) {
96 } BOOST_SCOPE_EXIT_END
98 xmlNodePtr root = xmlDocGetRootElement(xml);
100 throw Exception(
"XML document has no root node");
114 load(node, makeLower);
137 ChildMap::const_iterator child =
_childMap.find(name);
139 return child->second;
149 Properties::const_iterator
property =
_properties.find(name);
151 return property->second;
157 _name = node.name ?
reinterpret_cast<const char *
>(node.name) :
"";
158 _content = node.content ?
reinterpret_cast<const char *
>(node.content) :
"";
163 for (xmlAttrPtr attrib = node.properties; attrib; attrib = attrib->next) {
164 UString name (attrib->name ? reinterpret_cast<const char *>(attrib->name) :
"");
165 UString value(attrib->children ? reinterpret_cast<const char *>(attrib->children->content) :
"");
173 for (xmlNodePtr child = node.children; child; child = child->next) {
void add(const char *s,...) GCC_PRINTF(2
Generic interface for a readable data stream.
static int readStream(void *context, char *buffer, int len)
A class holding an UTF-8 string.
const UString & getName() const
const XMLNode * getParent() const
Return the parent node, or 0 if this is the root node.
const Children & getChildren() const
Return a list of children.
std::map< UString, UString > Properties
Exception that provides a stack of explanations.
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Utility templates and functions.
static void errorFuncUString(void *ctx, const char *msg,...)
const Properties & getProperties() const
Return all the properties on this node.
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
XML parsing helpers, using libxml2.
bool empty() const
Is the string empty?
UString getProperty(const UString &name, const UString &def="") const
Return a certain property on this node.
Basic reading stream interfaces.
const XMLNode * findChild(const UString &name) const
Find a child node by name.
void deinitXML()
Deinitialize the XML subsystem.
XMLParser(ReadStream &stream, bool makeLower=false, const UString &fileName="stream.xml")
Parse an XML file out of a stream.
const UString & getContent() const
const XMLNode & getRoot() const
Return the XML root node.
void initXML()
Initialize the XML subsystem.
static int closeStream(void *context)
XMLNode(_xmlNode &node, bool makeLower=false, XMLNode *parent=0)
void load(_xmlNode &node, bool makeLower)
void makeLower()
Convert the string to lowercase.
ScopedPtr< XMLNode > _rootNode