+/*******************************************************
+ * Unit test for the xml class
+ *
+ * test finding content in xml nodes
+ ******************************************************
+ *
+ */
+
+#include "xml.h"
+#include <assert.h>
+
+int main()
+{
+ xml doc;
+ xml_node root_node;
+ xml_node found_node;
+ String child_name;
+ String title_content;
+
+ const char xml_file[] = "xml_test01.xml";
+
+ std::cout << "Reading XML file " << xml_file << "\n";
+
+ doc.ParseFile("xml_test01.xml");
+
+ root_node = doc.RootNode();
+
+ std::cout << "Root element is " << root_node.name() << "\n";
+ assert(root_node.name() == "doc");
+
+ child_name = "book";
+ found_node = root_node.FindChildElement(child_name);
+ std::cout << "Child element " << child_name;
+ if (!found_node.is_a_node())
+ {
+ std::cout << " not";
+ }
+ std::cout << " found.\n";
+ assert(found_node.is_a_node() == true);
+
+ child_name = "report";
+ found_node = root_node.FindChildElement(child_name);
+ std::cout << "Child element " << child_name;
+ if (!found_node.is_a_node())
+ {
+ std::cout << " not";
+ }
+ std::cout << " found.\n";
+ std::cout.flush();
+ assert(found_node.is_a_node() == false);
+
+ // Find a child node three levels deep.
+ child_name = "book";
+ found_node = root_node.FindChildElement(child_name);
+ assert(found_node.is_a_node() == true);
+ found_node = found_node.FindChildElement("titlepage");
+ assert(found_node.is_a_node() == true);
+ found_node = found_node.FindChildElement("title"); // Two levels deeper
+ std::cout << "Name of title node = " << found_node.name() << "\n";
+ std::cout << "Content of title node = " << found_node.content() << "\n";
+
+ // Find multple child nodes
+
+ xml_node chapter_node;
+
+ child_name = "book";
+ found_node = root_node.FindChildElement(child_name);
+
+ for (int i = 0; i < 6; i++)
+ {
+ chapter_node = found_node.FindChildElement("chapter", i);
+ if (chapter_node.is_a_node())
+ {
+ std::cout << "Chapter node " << i << " found.\n";
+ }
+ else
+ {
+ std::cout << "Chapter node " << i << " is not found.\n";
+ }
+
+ }
+
+ return 0;
+}
+