27 #include "../common/Exception.h"
28 #include "../common/StringUtils.h"
29 #include "../common/Translator.h"
35 #include <boost/lexical_cast.hpp>
38 #include <xercesc/dom/DOMDocument.hpp>
39 #include <xercesc/dom/DOMDocumentType.hpp>
40 #include <xercesc/dom/DOMElement.hpp>
41 #include <xercesc/dom/DOMException.hpp>
42 #include <xercesc/dom/DOMImplementation.hpp>
43 #include <xercesc/dom/DOMImplementationRegistry.hpp>
44 #include <xercesc/dom/DOMText.hpp>
46 #include <xercesc/util/PlatformUtils.hpp>
47 #include <xercesc/util/OutOfMemoryException.hpp>
48 #include <xercesc/dom/DOM.hpp>
49 #include <xercesc/framework/StdOutFormatTarget.hpp>
50 #include <xercesc/framework/LocalFileFormatTarget.hpp>
51 #include <xercesc/framework/MemBufFormatTarget.hpp>
73 m_encoding = encoding;
79 #if XERCES_VERSION_MAJOR == 2
80 xercesc::DOMWriter* theSerializer = ( (xercesc::DOMImplementationLS*)m_impl)->createDOMWriter();
83 xercesc::DOMLSSerializer* theSerializer = ((xercesc::DOMImplementationLS*)m_impl)->createLSSerializer();
84 xercesc::DOMLSOutput* theOutput = 0;
87 xercesc::XMLFormatTarget* myFormTarget = 0;
93 myFormTarget =
new xercesc::StdOutFormatTarget();
95 myFormTarget =
new xercesc::LocalFileFormatTarget( m_uri.c_str() );
97 #if XERCES_VERSION_MAJOR == 2
98 theSerializer->writeNode( myFormTarget, *doc_ );
100 theOutput = ( (xercesc::DOMImplementationLS*)m_impl)->createLSOutput();
101 theOutput->setByteStream(myFormTarget);
102 theSerializer->write(m_doc, theOutput );
106 delete theSerializer;
109 catch(
const xercesc::OutOfMemoryException& )
112 delete theSerializer;
117 catch(
const xercesc::DOMException& e )
120 delete theSerializer;
123 std::string err =
XMLChToStr(e.getMessage()).getStr();
129 delete theSerializer;
142 m_impl = xercesc::DOMImplementationRegistry::getDOMImplementation(
StrToXMLCh(
"Core").getXMLCh());
148 if(m_rootNamespaceUri.empty())
149 m_doc = m_impl->createDocument(0,
StrToXMLCh(qName).getXMLCh(), 0);
151 m_doc = m_impl->createDocument(
StrToXMLCh(m_rootNamespaceUri).getXMLCh(),
StrToXMLCh(qName).getXMLCh(), 0);
153 m_doc->setXmlStandalone(m_standalone);
155 m_elementSet.push_back(m_doc->getDocumentElement());
159 m_topElementSet.push_back(0);
161 catch(xercesc::DOMException& e)
163 std::string err =
XMLChToStr(e.getMessage()).getStr();
171 m_elementSet.push_back(m_doc->createElement(
StrToXMLCh(qName).getXMLCh()));
172 m_elementSet[m_topIndice]->appendChild(m_elementSet[++m_indice] );
175 m_topElementSet.push_back(m_topIndice);
178 m_topIndice = m_indice;
181 catch(
const xercesc::OutOfMemoryException& )
185 catch(
const xercesc::DOMException& e )
187 std::string err =
XMLChToStr(e.getMessage()).getStr();
200 m_elementSet.push_back(m_doc->createElement(
StrToXMLCh(qName).getXMLCh()));
201 m_elementSet[m_topIndice]->appendChild(m_elementSet[++m_indice]);
204 m_topElementSet.push_back(m_topIndice);
210 catch(
const xercesc::DOMException& e)
216 throw te::common::Exception(
TE_TR(
"An error occurred adding the element: ") + ( qName.empty() ? std::string(
"[empty]" ) : qName ));
222 writeElement(qName, boost::lexical_cast<std::string>(value));
227 writeElement(qName, boost::lexical_cast<std::string>(value));
232 writeElement(qName, boost::lexical_cast<std::string>(value));
237 writeElement(qName, boost::lexical_cast<std::string>(value));
242 writeElement(qName, boost::lexical_cast<std::string>(value));
249 m_elementSet[m_topIndice]->setAttribute(
StrToXMLCh(attName).getXMLCh(),
StrToXMLCh(value).getXMLCh());
251 catch(
const xercesc::DOMException& e)
257 throw te::common::Exception(
TE_TR(
"An error occurred adding the attribute: ") + ( attName.empty() ? std::string(
"[empty]" ) : attName ));
263 writeAttribute(attName, boost::lexical_cast<std::string>(value));
268 writeAttribute(attName, boost::lexical_cast<std::string>(value));
273 writeAttribute(attName, boost::lexical_cast<std::string>(value));
278 writeAttribute(attName, boost::lexical_cast<std::string>(value));
283 writeAttribute(attName, boost::lexical_cast<std::string>(value));
293 addText(boost::lexical_cast<std::string>(value));
298 addText(boost::lexical_cast<std::string>(value));
303 addText(boost::lexical_cast<std::string>(value));
308 addText(boost::lexical_cast<std::string>(value));
313 addText(boost::lexical_cast<std::string>(value));
318 m_topIndice = m_topElementSet.at( m_topIndice );
325 xercesc::DOMText* domText = m_doc->createTextNode(
StrToXMLCh(qValue).getXMLCh());
326 m_elementSet[m_indice]->appendChild(domText);
328 catch(
const xercesc::DOMException& e)
A class for converting a standard string to a Xerces string (XMLCh).
void writeStartElement(const std::string &qName)
A class for converting a standard string to a Xerces string (XMLCh).
void addText(const std::string &qValue)
Adds a XML value to the last inserted element.
void writeStartDocument(const std::string &encoding, const std::string &standalone)
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
#define TE_TR(message)
It marks a string in order to get translated.
void writeElement(const std::string &qName, const std::string &value)
A class for converting a Xerces string (XMLCh) to a standard string.
A class for converting a Xerces string (XMLCh) to a standard string.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Writer()
Default constructor.
void writeEndElement(const std::string &qName)
void writeValue(const std::string &value)
void writeAttribute(const std::string &attName, const std::string &value)