Sorry, originally I was passing format to the XMLSerializer:
XMLSerializer serial = new XMLSerializer(new
BufferedWriter(res.getWriter()), format);
However the serialized output is on a single line. I also tried the
following code, avoiding use of XMLSerializer:
[...]
System.setProperty(DOMImplementationRegistry.PROPERTY,
"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS)
registry.getDOMImplementation("LS");
LSOutput out = impl.createLSOutput();
out.setByteStream(res.getOutputStream());
LSSerializer writer = impl.createLSSerializer();
writer.write(xhtmlDoc, out);
DOMImplementation implementation =
DOMImplementationRegistry.newInstance().getDOMImplementation("XML 3.0");
DOMImplementationLS feature = (DOMImplementationLS)
implementation.getFeature("LS", "3.0");
LSSerializer serializer = feature.createLSSerializer();
LSOutput output = feature.createLSOutput();
output.setByteStream(res.getOutputStream());
serializer.write(xhtmlDoc, output);
[...]
(Leaving away "System.setProperty(...)" would cause getDOMImplementation
return NULL.)
Output is still on a single line. I guess that this is caused by how I am
writing the serialized output to the servlet's response, rather then how the
serialization is configured. Do you have any ideas?
Thanks for your help!
-Felix
Michael Glavassevich-3 wrote:
>
>
> Felix,
>
> In the code snippet you're creating and configuring an OutputFormat and
> then passing a new and entirely different instance of OutputFormat to the
> XMLSerializer. If this is what you're really doing it's not surprising
> that
> none of your settings take effect. Also, if this is a new application that
> you're writing I would encourage you to avoid using XMLSerializer. We
> deprecated this API [1] in Xerces-J 2.9.0. It's better to use standard
> APIs
> such as DOM Level 3 or the JAXP Transform API for DOM serialization.
>
> Thanks.
>
> [1] http://xerces.apache.org/xerces2-j/faq-general.html#faq-6
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: [EMAIL PROTECTED]
> E-mail: [EMAIL PROTECTED]
>
> jfs <[EMAIL PROTECTED]> wrote on 11/16/2008 11:14:10 AM:
>
>> Hi,
>>
>> I want to serialize a Document object to XML using the following code:
>>
>> [...]
>> OutputFormat format = new OutputFormat(xhtmlDoc);
>> format.setIndenting(true);
>> format.setPreserveSpace(true);
>> format.setLineSeparator(System.getProperty("line.separator"));
>> format.setMethod("text/xhtml");
>>
>> XMLSerializer serial = new XMLSerializer(new
>> BufferedWriter(res.getWriter()), new OutputFormat());
>> DOMSerializer domserial = serial.asDOMSerializer();
>> domserial.serialize(xhtmlDoc);
>> [...]
>>
>> res is a HttpServletResponse object. The serialized XML is submitted to
> the
>> client and should be pretty printed. What I get is the complete serialize
>> output on a single line.
>>
>> What do I have to do?
>>
>> Thanks!
>> -Felix
>> --
>> View this message in context: http://www.nabble.com/No-newlines-in-
>> DOM-serialization-tp20526791p20526791.html
>> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
View this message in context:
http://www.nabble.com/No-newlines-in-DOM-serialization-tp20526791p20528951.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]