00001 #include <iostream> 00002 00003 #include "SDXDocumentBuilder.h" 00004 #include "SDXException.h" 00005 00006 using namespace SDX::Helpers; 00007 00008 DocumentBuilder::DocumentBuilder() : 00009 m_document(0) 00010 { 00011 } 00012 00013 SDX::Document* DocumentBuilder::getDocument(){ 00014 return m_document; 00015 } 00016 00017 void DocumentBuilder::startDocument(){ 00018 m_document = new Document; 00019 } 00020 00021 void DocumentBuilder::startNode(std::string nodeName){ 00022 m_nodes.push_back(new Node(nodeName)); 00023 } 00024 00025 void DocumentBuilder::writeAttribute(std::string name, std::string value){ 00026 if(m_nodes.size() > 0) 00027 m_nodes.back()->addAttribute(name, value); 00028 else 00029 throw SDX::Exception(SDX::Exception::ContentHandlerError, "Can't write attribute"); 00030 } 00031 00032 void DocumentBuilder::endNode(){ 00033 if(m_nodes.size() == 1) 00034 m_document->addChild(m_nodes.back()); 00035 else if(m_nodes.size() > 1) 00036 (*(--(--m_nodes.end())))->addChild(m_nodes.back()); 00037 else 00038 throw SDX::Exception(SDX::Exception::ContentHandlerError, "Can't end node when no nodes are started"); 00039 00040 m_nodes.pop_back(); 00041 }
1.5.8