You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Thomas Greenwood <tg...@exel.co.uk> on 2003/05/06 12:34:48 UTC

XMLSerializer attributes and carriage returns - bug?

I have an XML document that contains carriage returns and line feeds in
attributes.  When I serialize this document with XMLSerializer these
carriage returns and line feeds appear in the output as exactly that - but
this then causes problems using the document as an XSLT, escaping the
carriage returns and line feeds stops any problems.  I have written some
code that should fix these problems, but was this by design or is this a
bug?  If this is a bug then I'll send my new code sample in with a bug
report, if not is there any way to get the current XMLSerializer to escape
the carriage returns and line feeds in attributes (does not look like there
is any code to do this)?

Thanks


************************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom
they are addressed. Any views or opinions are solely those of
the author and do not necessarily represent those of Exel
Computer Systems plc. If you have received this email in error
please notify Customer Services on 0115 946 0101.
************************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: XMLSerializer attributes and carriage returns - bug?

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Tue, 2003-05-06 at 22:34, Thomas Greenwood wrote:
> I have an XML document that contains carriage returns and line feeds in
> attributes.  When I serialize this document with XMLSerializer these
> carriage returns and line feeds appear in the output as exactly that - but
> this then causes problems using the document as an XSLT, escaping the
> carriage returns and line feeds stops any problems.  I have written some
> code that should fix these problems, but was this by design or is this a
> bug?  If this is a bug then I'll send my new code sample in with a bug
> report, if not is there any way to get the current XMLSerializer to escape
> the carriage returns and line feeds in attributes (does not look like there
> is any code to do this)?

Do you mean that you have done:

Element someElement = doc.createElement("e");
someElement.setAttribute("foo", "abc\ndef");

then tried to serialize a document containing the above attribute,
hoping to get this?

  <e foo="abc&#x0a;def"/>

but instead got this?

  <e foo="abc
def"/>




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: XMLSerializer attributes and carriage returns - bug?

Posted by Joseph Kesselman <ke...@us.ibm.com>.
> When I serialize this document with XMLSerializer these
> carriage returns and line feeds appear in the output as exactly that - 
but
> this then causes problems using the document as an XSLT

It's hard to offer specific advice without seeing a specific example, but:

1) Remember that XML normalizes whitespace, and an XSLT stylesheet is an 
XML document. You may indeed have to escape some characters to keep them 
from being normalized away, if that's what you want.

2) Make sure you understand XSLT's rules for handling whitespace. They're 
somewhat complicated, since they involve which XSLT element the whitespace 
appears in, the <xsl:strip-space> and <xsl:preserve-space> directives, and 
the xml:space attribute (if present in the document).


______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more. 
"may'ron DaroQbe'chugh vaj bIrIQbej"  ("Put down the squeezebox and nobody 
gets hurt.")