Hi Neil,

"Neil Aggarwal" <[EMAIL PROTECTED]> wrote on 08/04/2006 05:36:05 PM:

> Hello:
> 
> I am using XMLSerializer with OutputFormat to format
> my XML into a string using this code:
> 
>     /* document contains a Document object */
> 
>     CharArrayWriter writer = new CharArrayWriter();
>     OutputFormat outputFormat = new OutputFormat("xml","utf-8",true);
>     XMLSerializer serializer = new XMLSerializer(writer,outputFormat);
>     serializer.serialize(document);
>     writer.close();
> 
>     /* writer.toString() gives me the XML formatted in a string */
> 
> When the text content of a tag is empty, I am getting
> this in the output:
> 
>    <TagName/>
> 
> I would like to generate this output instead:
>    <TagName></TagName>
> 
> Any ideas?

The serializer will always write an element without content as an empty 
tag. There's no configuration parameter for changing that behaviour though 
I suppose you could try fooling the serializer into believing there is 
content by attaching empty text nodes to each element you want written as 
<TagName></TagName>.

> I know the first form is correct and conformant, but I don't control
> the other side's parsing code.
> 
> Thanks,
>    Neil
> 
> --
> Neil Aggarwal, (214)986-3533, www.JAMMConsulting.com
> FREE! Eliminate junk email and reclaim your inbox.
> Visit http://www.spammilter.com for details.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

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

Reply via email to