W3C home > Mailing lists > Public > html-tidy@w3.org > January to March 2003

FW: Why is space removed?

From: Michael Goldberg <MGoldberg@yet2.com>
Date: Wed, 22 Jan 2003 08:31:51 -0800
Message-ID: <D090FE9586C9D4119E4E00A02493157AB5BD77@ferris.tahoe.yet2.com>
To: "'html-tidy@w3.org'" <html-tidy@w3.org>

Reposting, as I still have this issue, and would love to see a response.  Is
there a separate forum to discuss JTidy?  I apologize in advance if this is
not the correct place to discuss JTidy matters.

Michael S. Goldberg


I am using JTidy to parse an input string into an Element.  Later, when I
serialize the Element back into a String, I lose a space.  Is there an
option I can specify so as not to lose the space?

In the sample code provided below, I lose the space just prior to the letter
"C".  I'm pretty sure the problem is introduced in the first part (the
parsing) rather than the latter part (the serializing).

Interestingly, if I change my input to "<html><title/><body>A <b>B</b>
C</body></html>" and use setXmlTags( false ), the space is not lost.  Why?

Michael S. Goldberg

Sample Code:

Tidy tidyInstance = new Tidy();
tidyInstance.setXmlTags( true );

String inString = "<temp>A <b>B</b> C</temp>";
ByteArrayInputStream in = new ByteArrayInputStream( inString.getBytes() );

// Use JTidy to parse the input into a Document
Document document = tidyInstance.parseDOM( in, null );
Element	documentElement = document.getDocumentElement();

// Setup an output format for the makeSerializer() call below
OutputFormat outputFormat = new OutputFormat();
outputFormat.setOmitXMLDeclaration( true );

// Set up a byteArrayOutputStream, the output of the makeSerializer() call
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

// Get a SerializerFactory for the makeSerializer() call below
SerializerFactory xmlSerializerFactory =
SerializerFactory.getSerializerFactory( Method.XML );

// Use serializer to convert the element into a String
XMLSerializer xmlSerializer = (XMLSerializer)
xmlSerializerFactory.makeSerializer( new OutputStreamWriter(
byteArrayOutputStream ), outputFormat );
xmlSerializer.serialize( documentElement );

System.out.println( byteArrayOutputStream );
Received on Wednesday, 22 January 2003 11:34:54 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:38:53 UTC