Dear all,

I am very new to Xerces and I was wondering if you could help me with a
problem that I am having?

I have some XML that is represented in a org.w3c.dom.Document and would
like to produce XML in the form of text. My problem is with the
formatting of the text that Xerces produces. I would like to have the
document formatted nicely to make reading it in a text editor more
pleasant. However, one of the elements within the Document has newline
characters that are significant (a vCard) and it seems that I cannot get
Xerces to format nicely and preserve the newlines in the vCard.

I am using Xerces 1.4.3

I would really like the output to look something like:

<p>
  <q>foo</q>
  <r>bar</r>
  <s>
    <vcard>
n:Public;John
org:ABC, Inc.
    </vcard>
  </s>
</p>

To produce the text I am using the following:

Document d;
Writer w;
OutputFormat of = new OutputFormat(d);
XMLSerializer s = new XMLSerializer(w, of);
s.serialize(d);

To indent I have tried using:

of.setIndenting(true);
of.setLineWidth(0);

This produces something like:

<p>
  <q>foo</q>
  <r>bar</r>
  <s>
    <vcard>n:Public;John org:ABC, Inc.</vcard>
  </s>
</p>

Now, to preserve newlines I can use:

of.setPreserveSpace(true);

But, that then results in something like:

<p><q>foo</q><r>bar</r><s><vcard>
n:Public;John
org:ABC, Inc.
</vcard></s></p>

So it seems that I cannot have both indenting and preserveSpace at the
same time.

The Javadoc for OutputFormat.setPreserveSpace says

"Sets space preserving as the default behavior. The default is space
stripping and all elements that do not specify otherwise or use the
default value will not preserve spaces."

I am curious about "that do not specify otherwise" and I am wondering if
that is the answer. However, I could not find out how to set newline
preserving on an element basis.

Thanks a lot for reading this email and I am hoping that you might be
able to help me.

Simon Bates.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to