views:

69

answers:

2

Hi there, I could find in Jdom api any function to create self closing xml tag like the <selfClosingTag /> below.

For example, I need to create the following content:

<parentTag>
  <selfClosingTag />
  <firstChild>......    </firstChild>
  <secondChild>......    </secondChild>
</parentTag>

Can someone please tell me how. Please tell me I should not do it because this kind of self-closing tag is required in mathml document.

Thanks, Chepukha

+1  A: 

Any element you create, that you don't add any child nodes to, will be empty. An empty element can be represented as <element/> or <element></element>. Which one shouldn't really matter.

mwittrock
Great! Thanks Json for the link and mwittrock for the explanation.
chepukha
IMHO: It matters at the moment you need to deal with really big XML file full of empty elements.
SourceRebels
@chepukha If this answer solved your problem, click the check mark.
Jason Orendorff
+1  A: 

It seems like modifying your XMLOutputter like this should do the trick:

outputter.setFormat(outputter.getFormat().setExpandEmptyElements(false));

See the javadoc for setExpandEmptyElements.

Jason Orendorff