From: Sam Moore Date: Wed, 30 Apr 2014 13:36:27 +0000 (+0800) Subject: Tester for loading document in XML format X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=bf0f1cab25fa460ad4716ca60c11abab78a52cbd;p=ipdf%2Fcode.git Tester for loading document in XML format Inspired by the fact that SVG and HTML are XML and I was trying to write about them in the Literature Notes. The pugixml library for C++ seems actually usable. Could do a number of fancy things using it, but really should get back to that Literature Review :S --- diff --git a/src/tests/test.xml b/src/tests/test.xml new file mode 100644 index 0000000..997638c --- /dev/null +++ b/src/tests/test.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/tests/xml.cpp b/src/tests/xml.cpp new file mode 100644 index 0000000..a9335cd --- /dev/null +++ b/src/tests/xml.cpp @@ -0,0 +1,47 @@ +#include "main.h" +#include "../../contrib/pugixml-1.4/src/pugixml.hpp" +#include "../../contrib/pugixml-1.4/src/pugixml.cpp" + +using namespace std; + +/** + * This tester reads XML and uses it to produce rectangles in our viewer + * We use pugixml because I really didn't feel like implementing an XML parser + */ +int main(int argc, char ** argv) +{ + pugi::xml_document doc_xml; + Document doc; + pugi::xml_parse_result result = doc_xml.load(cin); // load from stdin + + if (!result) + { + Fatal("XML from stdin has errors: %s", result.description()); + } + + Debug("pugixml load result was: %s", result.description()); + int count = 0; + for (pugi::xml_node rect : doc_xml.children("rect")) + { + + Real coords[4]; + const char * attrib_names[] = {"x", "y", "w", "h"}; + for (size_t i = 0; i < sizeof(attrib_names)/sizeof(char*); ++i) + { + coords[i] = rect.attribute(attrib_names[i]).as_float(); + } + + bool outline = false; + outline = rect.attribute("outline").as_bool(); + + Debug("rect node %d is {%lf, %lf, %lf, %lf} (%s)", count++, coords[0], coords[1], coords[2], coords[3], (outline) ? "outline" : "filled"); + doc.Add(outline?RECT_OUTLINE:RECT_FILLED, Rect(coords[0], coords[1], coords[2], coords[3])); + } + + + MainLoop(doc); + + + + return 0; +}