// Serialize envelope.
stringstream s;
- XMLHelper::serialize(env->marshall(), s);
+ s << *env;
// Send to peer.
m_transport->send(s);
delete[] sizes;
return buf;
}
+
+std::ostream& xmltooling::operator<<(std::ostream& ostr, const XMLCh* s)
+{
+ if (s) {
+ char* p=xmltooling::toUTF8(s);
+ ostr << p;
+ delete[] p;
+ }
+ return ostr;
+}
#include <xmltooling/base.h>
#include <string>
+#include <iostream>
#include <xercesc/util/XMLString.hpp>
using namespace xercesc;
extern XMLTOOL_API XMLCh* fromUTF8(const char* src);
/**
+ * Writes a Unicode string to an ASCII stream by transcoding to UTF8.
+ *
+ * @param ostr stream to write to
+ * @param s string to write
+ * @return reference to output stream
+ */
+ extern XMLTOOL_API std::ostream& operator<<(std::ostream& ostr, const XMLCh* s);
+
+ /**
* A minimal auto_ptr-like class that can copy or transcode a buffer into
* the local code page and free the result automatically.
*
#include <xercesc/util/XMLUniDefs.hpp>
using namespace xmltooling;
+using std::ostream;
static const XMLCh type[]={chLatin_t, chLatin_y, chLatin_p, chLatin_e, chNull };
return e;
}
-void XMLHelper::serialize(const DOMElement* e, std::string& buf)
+void XMLHelper::serialize(const DOMNode* n, std::string& buf)
{
static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };
static const XMLCh UTF8[]={ chLatin_U, chLatin_T, chLatin_F, chDigit_8, chNull };
XercesJanitor<DOMWriter> janitor(serializer);
serializer->setEncoding(UTF8);
MemBufFormatTarget target;
- if (!serializer->writeNode(&target,*e))
+ if (!serializer->writeNode(&target,*n))
throw XMLParserException("unable to serialize XML");
buf.erase();
buf.append(reinterpret_cast<const char*>(target.getRawBuffer()),target.getLen());
};
};
-void XMLHelper::serialize(const DOMElement* e, std::ostream& out)
+void XMLHelper::serialize(const DOMNode* n, std::ostream& out)
{
static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };
static const XMLCh UTF8[]={ chLatin_U, chLatin_T, chLatin_F, chDigit_8, chNull };
XercesJanitor<DOMWriter> janitor(serializer);
serializer->setEncoding(UTF8);
StreamFormatTarget target(out);
- if (!serializer->writeNode(&target,*e))
+ if (!serializer->writeNode(&target,*n))
throw XMLParserException("unable to serialize XML");
}
+
+ostream& xmltooling::operator<<(ostream& ostr, const DOMNode& node)
+{
+ XMLHelper::serialize(&node, ostr);
+ return ostr;
+}
+
+ostream& xmltooling::operator<<(ostream& ostr, const XMLObject& obj)
+{
+ return ostr << obj.marshall();
+}
#ifndef __xmltooling_xmlhelper_h__
#define __xmltooling_xmlhelper_h__
-#include <xmltooling/QName.h>
+#include <xmltooling/XMLObject.h>
#include <xercesc/dom/DOM.hpp>
#include <iostream>
static const XMLCh* getTextContent(const DOMElement* e);
/**
- * Serializes the DOM Element provided into a buffer using UTF-8 encoding and
+ * 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 e element to serialize
+ * @param n node to serialize
* @param buf buffer to serialize element into
*/
- static void serialize(const DOMElement* e, std::string& buf);
+ static void serialize(const DOMNode* n, std::string& buf);
/**
- * Serializes the DOM Element provided to a stream using UTF-8 encoding and
+ * 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 e element to serialize
+ * @param n node to serialize
* @param out stream to serialize element into
*/
- static void serialize(const DOMElement* e, std::ostream& out);
+ static void serialize(const DOMNode* n, std::ostream& out);
};
+ /**
+ * 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 ostr stream to serialize element into
+ * @return reference to output stream
+ */
+ extern XMLTOOL_API std::ostream& operator<<(std::ostream& ostr, const DOMNode& n);
+
+ /**
+ * Marshalls and serializes the XMLObject provided to a stream using UTF-8 encoding and
+ * the default XML serializer available. No manipulation or formatting is applied.
+ *
+ * <p>The marshaller operation takes no parameters.
+ *
+ * @param obj object to serialize
+ * @param ostr stream to serialize object into
+ * @return reference to output stream
+ */
+ extern XMLTOOL_API std::ostream& operator<<(std::ostream& ostr, const XMLObject& obj);
};
#endif /* __xmltooling_xmlhelper_h__ */