00001
00008 #include "xmlUtil/docMan/GDDDocMan.h"
00009 #include "xml/docMan/DocClient.h"
00010 #include <dom/DOM_Element.hpp>
00011 #include <dom/DOMString.hpp>
00012 #include "xml/Dom.h"
00013
00014 #include <string>
00015 #include <iostream>
00016 using namespace xmlUtil;
00017
00018 class MiniClient : public xml::DocClient {
00019 public:
00020 MiniClient() {m_name = "miniClient";}
00021 MiniClient(std::string name) : m_name(name) {}
00022 const std::string& getName() { return m_name;}
00023 void handleChild(DOM_Node node);
00024 ~MiniClient() {};
00025 private:
00026 std::string m_name;
00027 };
00028
00029 void MiniClient::handleChild(DOM_Node node) {
00030 if (node.getNodeType() == DOM_Node::ELEMENT_NODE) {
00031 DOM_Element& elt = static_cast<DOM_Element&>(node);
00032 DOMString eltName = node.getNodeName();
00033 std::cout << m_name
00034 << " found element <" << xml::Dom::transToChar(eltName) << ">"
00035 << std::endl;
00036 DOMString att = elt.getAttribute(DOMString("substituted"));
00037 if (att != DOMString()) {
00038 std::cout << "substituted = " << xml::Dom::transToChar(att) << std::endl;
00039 }
00040 }
00041 else {
00042 std::cout << "User client passed non-element node: TILT " << std::endl;
00043 }
00044 }
00045
00046 int main(int argc, char* argv[]) {
00047
00048
00049 std::string defFile("../xml/flight.xml");
00050 std::string* pFileName = &defFile;
00051 if (argc >= 2) pFileName = new std::string(argv[1]);
00052
00053
00054 MiniClient* myClient = new MiniClient("firstClient");
00055 MiniClient* myClient2 = new MiniClient("secondClient");
00056
00057
00058 std::cout << "Output from DocMan parsing " << std::endl;
00059 xml::DocMan* pMan = xml::DocMan::getPointer();
00060 pMan->regClient("constants", myClient);
00061 pMan->regClient("section", myClient);
00062 pMan->regClient("section", myClient2);
00063 pMan->regClient("source", myClient);
00064 pMan->parse(*pFileName);
00065
00066
00067 std::cout << std::endl << "Output from GGDDocMan parsing " << std::endl;
00068 xmlUtil::GDDDocMan* pGDDMan = xmlUtil::GDDDocMan::getPointer();
00069 pGDDMan->regClient("constants", myClient);
00070 pGDDMan->regClient("section", myClient);
00071 pGDDMan->regClient("idDict", myClient);
00072 pGDDMan->parse(*pFileName);
00073
00074 return 0;
00075 }