aui::xml#
XML parser library.
Detailed Description#
aui::xml is a small event-driven (SAX-like) XML reader. It does not build a document tree; instead, AXml::read
walks the input once and reports everything it meets to your visitors:
- IXmlDocumentVisitor receives the top-level elements and, optionally, the
<?xml ... ?>header; - IXmlEntityVisitor receives attributes, text and nested elements of one element;
- IXmlHeaderVisitor receives the attributes of the
<?xml ... ?>header.
#include <AUI/Xml/AXml.h>
#include <AUI/IO/AStringStream.h>
struct Item: IXmlEntityVisitor {
void visitAttribute(const AString& name, AString value) override {
ALogger::info("Xml") << name << " = " << value;
}
};
struct Document: IXmlDocumentVisitor {
_<IXmlEntityVisitor> visitEntity(AString entityName) override {
return _new<Item>();
}
};
AXml::read(_new<AStringStream>(AString("<item id=\"1\" title=\"Hello\"/>")), _new<Document>());
To link aui::xml to your project, add the xml component to auib_import and link aui::xml:
auib_import(aui https://github.com/aui-framework/aui COMPONENTS core xml VERSION ${AUI_VERSION})
aui_link(${PROJECT_NAME} PRIVATE aui::xml)
See Parsing XML for a walkthrough and the limitations of the parser. There is no XML writer in aui::xml.
Related Pages#
-
Visits an xml entity (element).
-
Xml header visitor.
-
Xml document visitor.
-
Thrown when a parse error occur.