1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
41 #include <anna/core/core.hpp>
42 #include <anna/xml/xml.hpp>
44 #include <anna/app/Application.hpp>
46 class Test : public app::Application {
51 void run () throw (anna::RuntimeException);
56 int main (int argc, const char** argv)
58 CommandLine& commandLine (CommandLine::instantiate ());
61 xml::functions::initialize ();
64 commandLine.initialize (argv, argc);
65 commandLine.verify ();
67 Logger::setLevel (Logger::Debug);
68 Logger::initialize ("XML", new TraceWriter ("file.trace", 2048000));
72 catch (Exception& ex) {
73 cout << ex.asString () << endl;
81 app::Application ("testfunctions", "Checking trace system", "1.0")
83 CommandLine& commandLine (CommandLine::instantiate ());
85 commandLine.add ("document", CommandLine::Argument::Mandatory, "XML document");
86 commandLine.add ("dtd", CommandLine::Argument::Optional, "DTD file");
90 throw (RuntimeException)
92 CommandLine& commandLine (CommandLine::instantiate ());
94 xml::DocumentFile xmlDoc;
96 xml::Compiler xmlCompiler;
100 xmlDoc.initialize (commandLine.getValue ("document"));
102 if (commandLine.exists ("dtd")) {
103 xmlDTD.initialize (commandLine.getValue ("dtd"));
108 string msg ("DTD: ");
109 msg += (withDTD == true) ? "true": "false";
110 msg += " | Document: ";
111 msg += anna::functions::asString (xmlDoc.getContent (), 24);
112 Logger::debug (msg, ANNA_FILE_LOCATION);
115 const xml::Node* root = (withDTD) ? parser.apply (xmlDoc, xmlDTD): parser.apply (xmlDoc);
116 const xml::Node* node;
118 cout << "Root: " << root->asString () << endl;
120 for (xml::Node::const_child_iterator ii = root->child_begin (), maxii = root->child_end (); ii != maxii; ii ++) {
121 node = xml::Node::node (ii);
122 cout << "Level 1 - Node: " << node->asString () << endl;
125 cout << "xml::Compiler (Default= xml::Compiler::Mode::Visual): " << endl << xmlCompiler.apply (root) << endl << endl;
127 xml::Node* root2 = new xml::Node ("sample");
129 node2 = root2->createChild ("theNode");
130 node2->createAttribute ("attr1", 1222);
131 node2->createText ("text");
132 node2->createAttribute ("Empty", (char*) NULL);
135 cout << "xml::Compiler2: " << endl << xmlCompiler.apply (root2) << endl << endl;
137 const char* compact = xmlCompiler.apply (xmlDoc, root, xml::Compiler::Mode::Compact);
138 cout << "xml::Compiler (Compact): " << endl << compact << endl << endl;
140 xml::DocumentMemory memoDoc;
142 DataBlock doc (compact, anna_strlen (compact), false);
144 memoDoc.initialize (doc);
145 root = (withDTD) ? parser.apply (memoDoc, xmlDTD): parser.apply (memoDoc);
146 for (xml::Node::const_child_iterator ii = root->child_begin (), maxii = root->child_end (); ii != maxii; ii ++) {
147 node = xml::Node::node (ii);
148 cout << "Level 1 - Memo-Node: " << node->asString () << endl;
150 cout << "xml::CompilerMemo: " << endl << xmlCompiler.apply (root) << endl << endl;
152 memoDoc.initialize (compact);