3

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

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
chepukha
  • 2,371
  • 3
  • 28
  • 40

2 Answers2

4

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
  • 2,871
  • 1
  • 17
  • 20
2

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
  • 42,793
  • 6
  • 62
  • 96