XML Parser
This is an XML parser I wrote because I wasn't happy with the options available. It's works well, but like several of my other "throw things together until it works" projects, it is a mess.
Here is an example:
xml::Document doc;
xml::Document::ParseStatus status = doc.parse( util::getFileContents( "file.xml" ) );
if ( !status.success )
{
std::cerr << "Failed to load XML: " << status.message << " @ " << status.loc << std::endl;
}
else
{
xml::Node& root = doc.getRootNode();
for ( auto it = root.getChildren().begin(); it != root.getChildren().end(); ++it )
{
xml::Node& node = ( * it->get() );
if ( node.getName() == "category" )
{
std::string catName = xml::getAttribute( node, "name" );
// Process...
}
}
}
xml::Document::ParseStatus status = doc.parse( util::getFileContents( "file.xml" ) );
if ( !status.success )
{
std::cerr << "Failed to load XML: " << status.message << " @ " << status.loc << std::endl;
}
else
{
xml::Node& root = doc.getRootNode();
for ( auto it = root.getChildren().begin(); it != root.getChildren().end(); ++it )
{
xml::Node& node = ( * it->get() );
if ( node.getName() == "category" )
{
std::string catName = xml::getAttribute( node, "name" );
// Process...
}
}
}
You can find the source code here.