【问题标题】:JDOM: creating element from string, which contain xml-codeJDOM:从字符串创建元素,其中包含 xml 代码
【发布时间】:2011-09-02 14:19:25
【问题描述】:

我正在使用 jdom 将一些文本输入解析为 xml。它的结构如下:

<item>
  <text>Some description</text>
  <options .... />
</item>
<item>
  <text>Some description 2</text>
  <options .... />
</item>

然后,我需要一个常规的 w3c.dom 对象。我正在使用此代码:

    DOMOutputter domOutputter = new DOMOutputter();
    org.w3c.dom.Document w3cDoc = domOutputter.output( doc );

我正在使用此代码创建元素:

Element desc = new Element("tekst");
String description = //some function returning string
desc.addContent(description);
e.setContent(desc);

其中 e 是新元素(“item”)

它工作正常,但问题是当用户在“描述”中插入一些 xml 标签时。我想处理它。我的输出如下:

<text>&lt;bold&gt;description&lt;/bold&gt;</text>

有没有办法在创建元素时自动解析这些标签? 从 w3cDoc 我正在使用 DOMSource 创建 Source 并且需要进一步转换。也许我应该替换转义括号?

__

dce

【问题讨论】:

    标签: xml escaping jdom


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 2015-12-22
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 2020-02-01
    相关资源
    最近更新 更多