27 #include "../common/Exception.h" 28 #include "../common/StringUtils.h" 29 #include "../core/encoding/CharEncoding.h" 30 #include "../core/translator/Translator.h" 39 #include <boost/lexical_cast.hpp> 42 #include <xercesc/dom/DOMDocument.hpp> 43 #include <xercesc/dom/DOMDocumentType.hpp> 44 #include <xercesc/dom/DOMElement.hpp> 45 #include <xercesc/dom/DOMException.hpp> 46 #include <xercesc/dom/DOMImplementation.hpp> 47 #include <xercesc/dom/DOMImplementationRegistry.hpp> 48 #include <xercesc/dom/DOMText.hpp> 50 #include <xercesc/util/PlatformUtils.hpp> 51 #include <xercesc/util/OutOfMemoryException.hpp> 52 #include <xercesc/dom/DOM.hpp> 53 #include <xercesc/framework/StdOutFormatTarget.hpp> 54 #include <xercesc/framework/LocalFileFormatTarget.hpp> 55 #include <xercesc/framework/MemBufFormatTarget.hpp> 83 #if XERCES_VERSION_MAJOR == 2 84 xercesc::DOMWriter* theSerializer = ( (xercesc::DOMImplementationLS*)
m_impl)->createDOMWriter();
87 xercesc::DOMLSSerializer* theSerializer = ((xercesc::DOMImplementationLS*)
m_impl)->createLSSerializer();
88 xercesc::DOMLSOutput* theOutput =
nullptr;
91 xercesc::XMLFormatTarget* myFormTarget =
nullptr;
96 myFormTarget =
new xercesc::StdOutFormatTarget();
98 myFormTarget =
new xercesc::MemBufFormatTarget();
100 #if XERCES_VERSION_MAJOR == 2 101 theSerializer->writeNode( myFormTarget, *doc_ );
103 theOutput = ( (xercesc::DOMImplementationLS*)
m_impl)->createLSOutput();
104 theOutput->setByteStream(myFormTarget);
105 theSerializer->write(
m_doc, theOutput );
106 std::string xmlstring = (
char*)((xercesc::MemBufFormatTarget*)myFormTarget)->getRawBuffer();
112 delete theSerializer;
115 catch(
const xercesc::OutOfMemoryException& )
118 delete theSerializer;
123 catch(
const xercesc::DOMException& e )
126 delete theSerializer;
129 std::string err =
XMLChToStr(e.getMessage()).getStr();
135 delete theSerializer;
148 m_impl = xercesc::DOMImplementationRegistry::getDOMImplementation(
StrToXMLCh(
"Core").getXMLCh());
167 catch(xercesc::DOMException& e)
169 std::string err =
XMLChToStr(e.getMessage()).getStr();
187 catch(
const xercesc::OutOfMemoryException& )
191 catch(
const xercesc::DOMException& e )
193 std::string err =
XMLChToStr(e.getMessage()).getStr();
216 catch(
const xercesc::DOMException& e)
222 throw te::common::Exception(
TE_TR(
"An error occurred adding the element: ") + ( qName.empty() ? std::string(
"[empty]" ) : qName ));
228 writeElement(qName, boost::lexical_cast<std::string>(value));
233 writeElement(qName, boost::lexical_cast<std::string>(value));
238 writeElement(qName, boost::lexical_cast<std::string>(value));
243 writeElement(qName, boost::lexical_cast<std::string>(value));
248 writeElement(qName, boost::lexical_cast<std::string>(value));
257 catch(
const xercesc::DOMException& e)
263 throw te::common::Exception(
TE_TR(
"An error occurred adding the attribute: ") + ( attName.empty() ? std::string(
"[empty]" ) : attName ));
299 addText(boost::lexical_cast<std::string>(value));
304 addText(boost::lexical_cast<std::string>(value));
309 addText(boost::lexical_cast<std::string>(value));
314 addText(boost::lexical_cast<std::string>(value));
319 addText(boost::lexical_cast<std::string>(value));
331 xercesc::DOMText* domText =
m_doc->createTextNode(
StrToXMLCh(qValue).getXMLCh());
334 catch(
const xercesc::DOMException& e)
std::string m_rootNamespaceUri
A class for converting a standard string to a Xerces string (XMLCh).
std::size_t m_indice
Index to build the ElementSet vector.
void writeStartElement(const std::string &qName)
std::vector< std::size_t > m_topElementSet
This vector gives the parent node of each element.
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.
static std::string fromUTF8(const std::string &src)
Convert a string in UTF-8 to the current locale encoding.
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.
std::vector< XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * > m_elementSet
Vector that contains all the elements (nodes).
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::size_t m_topIndice
Index of the parent node.
XERCES_CPP_NAMESPACE_QUALIFIER DOMImplementation * m_impl
DOM element - implementation.
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)
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * m_doc
DOM element - document.