return e;
}
-void XMLHelper::serialize(const DOMNode* n, std::string& buf)
+void XMLHelper::serialize(const DOMNode* n, std::string& buf, bool pretty)
{
static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };
static const XMLCh UTF8[]={ chLatin_U, chLatin_T, chLatin_F, chDigit_8, chNull };
DOMWriter* serializer=(static_cast<DOMImplementationLS*>(impl))->createDOMWriter();
XercesJanitor<DOMWriter> janitor(serializer);
serializer->setEncoding(UTF8);
+ if (pretty && serializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, pretty))
+ serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, pretty);
MemBufFormatTarget target;
if (!serializer->writeNode(&target,*n))
throw XMLParserException("unable to serialize XML");
};
};
-ostream& XMLHelper::serialize(const DOMNode* n, ostream& out)
+ostream& XMLHelper::serialize(const DOMNode* n, ostream& out, bool pretty)
{
static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };
static const XMLCh UTF8[]={ chLatin_U, chLatin_T, chLatin_F, chDigit_8, chNull };
DOMWriter* serializer=(static_cast<DOMImplementationLS*>(impl))->createDOMWriter();
XercesJanitor<DOMWriter> janitor(serializer);
serializer->setEncoding(UTF8);
+ if (pretty && serializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, pretty))
+ serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, pretty);
StreamFormatTarget target(out);
if (!serializer->writeNode(&target,*n))
throw XMLParserException("unable to serialize XML");
* Serializes the DOM node provided into a buffer using UTF-8 encoding and
* the default XML serializer available. No manipulation or formatting is applied.
*
- * @param n node to serialize
- * @param buf buffer to serialize element into
+ * @param n node to serialize
+ * @param buf buffer to serialize element into
+ * @param pretty enable pretty printing if supported
*/
- static void serialize(const xercesc::DOMNode* n, std::string& buf);
+ static void serialize(const xercesc::DOMNode* n, std::string& buf, bool pretty=false);
/**
* Serializes the DOM node provided to a stream using UTF-8 encoding and
* the default XML serializer available. No manipulation or formatting is applied.
*
- * @param n node to serialize
- * @param out stream to serialize element into
+ * @param n node to serialize
+ * @param out stream to serialize element into
+ * @param pretty enable pretty printing if supported
* @return reference to output stream
*/
- static std::ostream& serialize(const xercesc::DOMNode* n, std::ostream& out);
+ static std::ostream& serialize(const xercesc::DOMNode* n, std::ostream& out, bool pretty=false);
};
/**