terraforma/libterra — pull request #7 by tgascoigne (2013-01-29 19:05:39+00:00)
Title: XML Wrapper

This is almost a 1:1 wrapper around pugixml, but the interface makes sense so if need be we can swap pugixml out and rewrite the internals of interface.

I have included all functionality necessary to unmarshal an XML document from a file, and to traverse the tree extracting values and attributes. I have not yet considered modifying and storing the tree back to an XML document in order to simplify things for the time being.

@MiniAl: You need to set up the Visual Studio projects for pugixml and make sure that it builds successfully. Here's a sample program I was using to test the interface which might come in handy:

```
#include
#include

int main(int _argc, char *_argv[])
{
LibTerra::tfXMLDocument doc;
bool success = doc.Parse("/home/tom/terraforma/documentation/specification/draft_data_formats/road_map.xml");
if (!success) {
std::cerr << "XML Parse failed with error: " << doc.LastError() << std::endl;
return 1;
}
LibTerra::tfXMLNode root = doc.Child("roadmap");
const char* versionString = root.Attribute("version").Value();
std::cout << "Version: " << versionString << std::endl;
for (LibTerra::tfXMLNode node = root.FirstChild(); node.Valid(); node = node.NextSibling()) {
std::cout << "Found node with name: " << node.Name() << std::endl;
}
return 0;
}
```

And here's the expected output:

```
tom@riverwood ~/terraforma (development*^) $ bin/wires
Version: 0.1.0
Found node with name: width
Found node with name: height
Found node with name: nodes
Found node with name: relations
```