1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
13 #include <anna/core/core.hpp>
14 #include <anna/xml/xml.hpp>
16 #include <anna/app/Application.hpp>
18 class Test : public app::Application {
23 void run () throw (anna::RuntimeException);
28 int main (int argc, const char** argv)
30 CommandLine& commandLine (CommandLine::instantiate ());
33 xml::functions::initialize ();
36 commandLine.initialize (argv, argc);
37 commandLine.verify ();
39 Logger::setLevel (Logger::Debug);
40 Logger::initialize ("XML", new TraceWriter ("file.trace", 2048000));
44 catch (Exception& ex) {
45 cout << ex.asString () << endl;
53 app::Application ("testfunctions", "Checking trace system", "1.0")
55 CommandLine& commandLine (CommandLine::instantiate ());
57 commandLine.add ("document", CommandLine::Argument::Mandatory, "XML document");
58 commandLine.add ("dtd", CommandLine::Argument::Optional, "DTD file");
62 throw (RuntimeException)
64 CommandLine& commandLine (CommandLine::instantiate ());
66 xml::DocumentFile xmlDoc;
68 xml::Compiler xmlCompiler;
72 xmlDoc.initialize (commandLine.getValue ("document"));
74 if (commandLine.exists ("dtd")) {
75 xmlDTD.initialize (commandLine.getValue ("dtd"));
81 msg += (withDTD == true) ? "true": "false";
82 msg += " | Document: ";
83 msg += anna::functions::asString (xmlDoc.getContent (), 24);
84 Logger::debug (msg, ANNA_FILE_LOCATION);
87 const xml::Node* root = (withDTD) ? parser.apply (xmlDoc, xmlDTD): parser.apply (xmlDoc);
88 const xml::Node* node;
90 cout << "Root: " << root->asString () << endl;
92 for (xml::Node::const_child_iterator ii = root->child_begin (), maxii = root->child_end (); ii != maxii; ii ++) {
93 node = xml::Node::node (ii);
94 cout << "Level 1 - Node: " << node->asString () << endl;
97 cout << "xml::Compiler (Default= xml::Compiler::Mode::Visual): " << endl << xmlCompiler.apply (root) << endl << endl;
99 xml::Node* root2 = new xml::Node ("sample");
101 node2 = root2->createChild ("theNode");
102 node2->createAttribute ("attr1", 1222);
103 node2->createText ("text");
104 node2->createAttribute ("Empty", (char*) NULL);
107 cout << "xml::Compiler2: " << endl << xmlCompiler.apply (root2) << endl << endl;
109 const char* compact = xmlCompiler.apply (xmlDoc, root, xml::Compiler::Mode::Compact);
110 cout << "xml::Compiler (Compact): " << endl << compact << endl << endl;
112 xml::DocumentMemory memoDoc;
114 DataBlock doc (compact, anna_strlen (compact), false);
116 memoDoc.initialize (doc);
117 root = (withDTD) ? parser.apply (memoDoc, xmlDTD): parser.apply (memoDoc);
118 for (xml::Node::const_child_iterator ii = root->child_begin (), maxii = root->child_end (); ii != maxii; ii ++) {
119 node = xml::Node::node (ii);
120 cout << "Level 1 - Memo-Node: " << node->asString () << endl;
122 cout << "xml::CompilerMemo: " << endl << xmlCompiler.apply (root) << endl << endl;
124 memoDoc.initialize (compact);