Search code examples
javadom4j

DOM4J unescape xml


How I can to add an xml element as text content with dom4j ? I have

public void updateTitle (Node titleNode){ // titleNode ==> <title></title>
String title = "<user_text>";
titleNode.setText(title);
. . . . .}

but I have bad content in title :

<title>&lt;user_text&gt;</title>

instead of

<title><user_text></title>

Solution

  • This is the escape sequence for the < and > characters because they are reserved characters in XML.

    From your question, it is unclear whether you really intend to have those characters in your title or not.

    When the XML is parsed back into straight text, those &lt; and &gt; will become < and > once again.