How can I create a self closing tag using JDOM
문제
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
해결책
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.
다른 팁
It seems like modifying your XMLOutputter
like this should do the trick:
outputter.setFormat(outputter.getFormat().setExpandEmptyElements(false));
See the javadoc for setExpandEmptyElements
.
제휴하지 않습니다 StackOverflow