00001
00002
00003
00004 #include "xml/XmlParser.h"
00005 #include "xml/Dom.h"
00006 #include "dom/DOM_Element.hpp"
00007 #include "dom/DOM_NodeList.hpp"
00008
00009 #include <string>
00010 #include <iostream>
00011 #include <fstream>
00012
00013
00014 int main(int argc, char* argv[]) {
00015 if (argc < 2) {
00016 std::cout << "Required first argument is xml file to be parsed"
00017 << std::endl;
00018 std::cout << "optional second argument is output file (- for stdout)"
00019 << std::endl;
00020 exit(0);
00021 }
00022
00023 xml::XmlParser* parser = new xml::XmlParser();
00024
00025 DOM_Document doc = parser->parse(argv[1]);
00026
00027 if (doc != 0) {
00028 std::cout << "Document successfully parsed" << std::endl;
00029
00030 if (argc > 2) {
00031 char *hyphen = "-";
00032 DOM_Element docElt = doc.getDocumentElement();
00033 std::ostream* out;
00034
00035 if (*(argv[2]) == *hyphen) {
00036 out = &std::cout;
00037 }
00038 else {
00039 char *filename = argv[2];
00040 out = new std::ofstream(filename);
00041 }
00042 *out << "Document source: " << std::string(argv[1]) << std::endl;
00043 *out << std::endl << "Straight print of document:" << std::endl;
00044 xml::Dom::printElement(docElt, *out);
00045 *out << std::endl << std::endl << "Add indentation and line breaks:"
00046 << std::endl;
00047 xml::Dom::prettyPrintElement(docElt, *out, "");
00048
00049 xml::Dom::prettyPrintElement(docElt, *out, "");
00050 }
00051 }
00052 delete parser;
00053 return(0);
00054 }
00055
00056
00057