added examples and cmake compilation #13

Closed
wants to merge 3 commits into
from
View
1 examples/.gitignore
@@ -0,0 +1 @@
+.DS_Store
View
11 examples/CMakeLists.txt
@@ -0,0 +1,11 @@
+project(abc)
+
+cmake_minimum_required(VERSION 2.6)
+
+include_directories(..)
+
+SET(EXE_NAME example1 example2 example3 example4)
+
+foreach (exe ${EXE_NAME})
+ add_executable(${exe} ${exe}.cpp ../tinyxml2.cpp)
+endforeach()
View
20 examples/example1.cpp
@@ -0,0 +1,20 @@
+#include "tinyxml2.h"
+#include <cstdio>
+
+using namespace tinyxml2;
+
+
+int main(void)
+{
+ XMLDocument doc;
+ doc.LoadFile( "../dream.xml" );
+ const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText();
+ printf( "Name of play (1): %s\n", title );
+
+ // Text is just another Node to TinyXML-2. The more
+ // general way to get to the XMLText:
+ XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText();
+ title = textNode->Value();
+ printf( "Name of play (2): %s\n", title );
+ return 0;
+}
View
15 examples/example2.cpp
@@ -0,0 +1,15 @@
+#include "tinyxml2.h"
+
+using namespace tinyxml2;
+
+int main (int argc, char * const argv[])
+{
+ XMLDocument doc;
+ if (doc.LoadFile("input_example_02.xml") == XML_SUCCESS)
+ {
+ XMLNode *node = doc.NewElement("foo");
+ doc.InsertEndChild(node);
+ doc.SaveFile("output_example_02.xml");
+ }
+ return 0;
+}
View
32 examples/example3.cpp
@@ -0,0 +1,32 @@
+#include "tinyxml2.h"
+#include <cstdio>
+
+using namespace tinyxml2;
+
+int main (int argc, char * const argv[])
+{
+ XMLDocument doc;
+
+ if (doc.LoadFile("input_example_03.xml") == XML_SUCCESS)
+ {
+ //search for a node named Hello
+ XMLNode *node = doc.FirstChildElement("Hello");
+ //read the text content of it and print it to stdout
+ XMLText* textNode = node->FirstChild()->ToText();
+ const char* title = textNode->Value();
+ printf( "Contents of Hello: %s\n", title );
+
+ //create a new node named foo
+ XMLNode *new_node = doc.NewElement("foo");
+ //add foo as child of Hello
+ node->InsertEndChild(new_node);
+ //add some text content to the "foo" node
+ new_node->InsertFirstChild(doc.NewText("bar"));
+
+ //save the output document
+ doc.SaveFile("output_example_03.xml");
+
+ }
+
+ return 0;
+}
View
26 examples/example4.cpp
@@ -0,0 +1,26 @@
+#include "tinyxml2.h"
+#include <cstdio>
+
+using namespace tinyxml2;
+
+int main (int argc, char * const argv[])
+{
+ XMLDocument doc;
+
+ if (doc.LoadFile(argv[1]) == XML_SUCCESS)
+ {
+ //search for a node named Hello
+ XMLElement *node = doc.RootElement();
+
+
+ for(XMLElement* current_node=node->FirstChildElement("type");current_node!=NULL;current_node=current_node->NextSiblingElement("type"))
+ {
+ const char* at = current_node->Attribute("id");
+ printf("id: %s\n",at);
+ }
+
+
+ }
+
+ return 0;
+}
View
4,546 examples/input_example_01.xml
4,546 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 examples/input_example_02.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" ?>
+<Hello>World</Hello>
View
3 examples/input_example_03.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" ?>
+<Hello>World</Hello>
+