如何使用 JDOM 创建自关闭标签

发布于 2024-09-14 22:56:44 字数 383 浏览 3 评论 0原文

我可以在 Jdom api 中找到任何创建自关闭 xml 标记的函数,如下面的

例如,我需要创建以下内容:

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

有人可以告诉我怎么做吗?请告诉我我不应该这样做,因为 mathml 文档中需要这种自闭合标签。

谢谢, 切普卡

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷情 2024-09-21 22:56:45

您创建的任何未添加任何子节点的元素都将为空。空元素可以表示为 。哪一个应该并不重要。

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.

离不开的别离 2024-09-21 22:56:45

看起来像这样修改您的 XMLOutputter 应该可以解决问题:

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

请参阅 setExpandEmptyElements 的 javadoc。

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

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

See the javadoc for setExpandEmptyElements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文