[xsd-users] start/end tags versus empty tag

Boris Kolpackov boris at codesynthesis.com
Tue May 18 07:03:05 EDT 2010


Hi Barrie,

Barrie Kovish <barrie.kovish at singularsoftware.com> writes:

> I'm using XSD tree mapping. I would like to be able to force empty 
> elements to be written out as start end tags instead of an empty tag,
> i.e. start/end tags:
> 
> <car></car>
> 
> instead of empty tag:
> 
> <car/>

There is no easy way to get this behavior. One thing that you can
do is to add a whitespace as the value of the element:

<car> </car>

This will work for elements that have complex content and for which
mixed is not set to true. For such elements whitespaces are ignored,
provided, of course, the other end will ignore them as well.

If this approach works for you, the best way to implement it would
probably be to serialize the object model to a DOM document, then
recursively traverse this document and add a space to every empty 
element. Once this is done, you can serialize the document to XML.

Boris



More information about the xsd-users mailing list