nxmlwriter.cpp

Go to the documentation of this file.
00001 // LICENSE: (Please see the file COPYING for details)
00002 //
00003 // NUS - Nemesis Utilities System: A C++ application development framework 
00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske
00005 //
00006 //  This file is part of NUS
00007 //
00008 //  This library is free software; you can redistribute it and/or
00009 //  modify it under the terms of the GNU Lesser General Public
00010 //  License as published by the Free Software Foundation version 2.1
00011 //  of the License.
00012 //
00013 //  This library is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //  Lesser General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU Lesser General Public
00019 //  License along with this library; if not, write to the Free Software
00020 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021 //
00022 #include "nxmlwriter.h"
00023 
00028 NXmlWriter::NXmlWriter(NXmlDocument *doc)
00029       : m_doc(NULL)
00030 { 
00031       if (!doc) { 
00032             throw NXmlException("Invalid XML Document: NULL pointer",
00033                          NException::XML, NXmlException::XML_INIT_ERROR);
00034       }
00035       
00036       m_doc = doc;
00037 }
00038 
00039 NXmlWriter::~NXmlWriter(void) { 
00040 
00041 }
00042 
00043 
00044 nint32 NXmlWriter::dump(NString *buffer, bool indent) {
00045       int size = 0; 
00046       xmlTextWriterPtr writer;
00047       xmlChar *ret;
00048 
00049       if (!buffer) { 
00050             throw NXmlException("Invalid return buffer: NULL", 
00051                          NException::XML, NXmlException::XML_INIT_ERROR);
00052       }
00053       writer = xmlNewTextWriterTree(m_doc->getXmlDoc(),
00054                                     m_doc->getRootNode().getNode(), 0);
00055       
00056       // 
00057       while (xmlTextWriterEndElement(writer) != -1) {
00058 
00059       }
00060       xmlTextWriterEndDocument(writer);
00061       xmlTextWriterFlush(writer);
00062       
00063       if (indent) { 
00064             xmlDocDumpFormatMemory(m_doc->getXmlDoc(), &ret, &size, 1);
00065       }
00066       else { 
00067             xmlDocDumpFormatMemory(m_doc->getXmlDoc(), &ret, &size, 0);
00068       }
00069       
00070       buffer->set(reinterpret_cast<const char *>(ret));
00071       
00072       return size;
00073 }
00074 

Generated on Wed Mar 5 23:10:36 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4