开发者

JDOM: creating element from string, which contain xml-code

I'm parsing some text input to xml using jdom. It have structure like:

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

Then, I need a regular w3c.dom object开发者_JAVA技巧. I'm using this code:

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

I'm creating element with this code:

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

Where e is new Element("item")

It works fine, but problem is when in "description" user inserts some xml tags. I'd like to handle it. I have output like:

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

Is there any way to automaticaly parse those tags when creating Element? From the w3cDoc I'm creating Source with DOMSource and it's needed for further transformation. Maybe there should I replace escaped brackets?

__

dce


Have you looked at http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html

specifically at

http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html#escapeAttributeEntities(java.lang.String)

http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html#escapeElementEntities(java.lang.String)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜