Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm going to assume that you're building an <code>org.w3c.Document</code>, and writing it using a serializer. If you're hand-building an XML string, you're all but guaranteed to be producing something that's almost-but-not-quite XML, and I strongly suggest fixing that first.</p> <p>That said, if you're writing to a stream from the serializer (and System.out is a stream), then you should be writing directly to the stream rather than writing to a string and printing that (which you'd do with a StringWriter). The reason for this is that the XML serializer will properly handle character encodings, while serializer to String to stream may not.</p> <hr> <p>If you're not currently building a DOM, and are concerned about the memory requirements of doing so, then I suggest looking at the Practical XML library (which I maintain), in particular the <a href="http://practicalxml.sourceforge.net/apidocs/net/sf/practicalxml/builder/package-frame.html" rel="nofollow noreferrer">builder</a> package. It uses lightweight nodes, that are then output via a serializer using a SAX transform.</p> <hr> <p>Edit in response to comment:</p> <p>OK, you've got the serializer covered with XStream. I'm next going to assume that you are calling <code>XStream.toXML(Object)</code> to produce the string, and recommend that you call the variant <code>toXML(Object, OutputStream)</code>, and pass it the actual output. The reason for this is that XML is very sensitive to character encoding, which is something that often breaks when converting strings to streams.</p> <p>This may, of course, cause issues with building your POST request, particularly if you're using a library that doesn't provide you an OutputStream.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload