Alex Rivera | Logout

How to prevent xml transformer to transform empty tags into single tag

Asked 2010-09-20T13:08:22.830
11

I'm using javax.xml.transform.Transformer class to transform the DOM source into XML string. I have some empty elements in DOM tree, and these become one tag which I don't want.

How do I prevent <sampletag></sampletag> from becoming <sampletag/>?

Edit
Report

1 Answer

2

If the process you are sending it through NEEDS the element not to be self-closing (which it should not), you can force the element not to be self-closing by placing content inside of it.

How does the PDF converter handle XML comments or processing instructions?

<sampletag>!<--Sample Comment--></sampletag>

<sampletag><?SampleProcessingInstruction?></sampletag>

answered 2010-09-20T16:47:59.593

Your Answer