Thank you both of you for your answers.<br><br><div class="gmail_quote">2013/1/9 Brenner, Mike <span dir="ltr"><<a href="mailto:mikeb@mitre.org" target="_blank">mikeb@mitre.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi Rolf,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Although you are technically right that we should always generate socially acceptable xml, I would like to add some caveats to your response.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">First, not all html can be translated to xhtml (for example, the html attribute “target” to generate a popup).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Second, there are many workarounds needed (for example,   and other symbols don’t exist in xhtml due to unfortunate choices of version numbers of included
documents in the standards).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Third, you don’t always have control over how the process using your xml will parse it, if at all.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Fourth, xml is often the lowest or second lowest protocol in a large number of protocols (for example, a URI inside a javascript string inside a javascript
block inside an xhtml, etc.)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">The key to making xml useful is being flexible enough to work around the bugs in all of these well-established tools (especially xml itself with its needless
vestiges of sgml and its inability to contain unparsed tags or use xml fragments). Therefore, sometimes it make sense to ask if an xml tool like jdom could provide some of those required workarounds.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">The alternative in cases like these might not suffice to demand more goodness in our output xml; the alternative might turn out to be to use json or yaml or
some other alternative to xml itself, when the tools are not flexible enough.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Mike Brenner<u></u><u></u></span></p>
<p class="MsoNormal"><a name="13c1f93255ab7cbb__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></a></p>
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"> <a href="mailto:jdom-interest-bounces@jdom.org" target="_blank">jdom-interest-bounces@jdom.org</a>
[mailto:<a href="mailto:jdom-interest-bounces@jdom.org" target="_blank">jdom-interest-bounces@jdom.org</a>] <b>On Behalf Of </b>Rolf Lear<br>
<b>Sent:</b> Wednesday, January 09, 2013 7:49 AM<br>
<b>To:</b> SoTaNeZ<br>
<b>Cc:</b> <a href="mailto:jdom-interest@jdom.org" target="_blank">jdom-interest@jdom.org</a><br>
<b>Subject:</b> Re: [jdom-interest] EscapeStrategy for in-text html tags not working<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">Hi there.<br>
<br>
Escaping "<" and other the other characters '>', '&', and '\r' is always done (with one exception...). The '\n' char is also sometimes replaced with \r\n.<br>
<br>
if (ch == '<' || ch == '>' || ch == '&' || ch == '\r' || ch == '\n'<br>
|| strategy.shouldEscape(ch)) {<br>
......<br>
}<br>
<br>
To do anything else would be to produce broken XML.<br>
<br>
What you want is (likelye to be) broken XML and JDOM is not designed to produce broken XML. Really the best way to solve your problem is to do the right handling of your output. The code using your XML should parse the data from your element and the parsing
process will un-escape the characters. The next best way to do things is to make the actual HTML content valid XHTML and to parse it and then add the Element content as JDOM objects to the JDOM tree, and then output the complete JDOM document normally.<br>
<br>
The wrong way to do it wold be to override/extend the AbstractXMLOutputProcessor and to 'hack' the code that does the escaping.<br>
<br>
TrAXEscapePI concept is designed to support obscure functionality in the XMLTransformation process (XSLT). Technically I think you *can* use this concept to support not-escaping by having the following JDOM content:<br>
<br>
Element emt = new Element("tag");<br>
emt.addContent(new ProcessingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING));<br>
emt.addContent(new Text("<html><body><p></body></html>"));<br>
emt.addContent(new ProcessingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING));<br>
<br>
Then you will need to set Format.setIgnoreTrAXExcapingPIs to false when you output the JDOM Content.<br>
<br>
The above is a *hack* and is not what I recommend that you do.<br>
<br>
Rolf<br>
<br>
<br>
<br>
On 09/01/2013 3:50 AM, SoTaNeZ wrote:<u></u><u></u></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-left:.5in">Hello. <u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">I have some XML elements which text is not plain, but contains some HTML tags.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">The thing is that when outputting these to an XML file the characters "<" and ">" are changed into "<" and ">" preventing its correct posterior HTML processing.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I tried using this EscapeStrategy:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">------------------<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>class EscapeSimbolos implements EscapeStrategy {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>public boolean shouldEscape(char car) {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>switch (car) {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>case '<':<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>return false;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>case '>':<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>return false;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>default:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>return false;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>}<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>}<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>}<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">------------------<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">but with no effect. The code within the two case statements is never reached, but the method is executed, so it seems that these characters are converted before the EscapeStrategy gets into action, or maybe I am
doing something wrong.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">This is the code to set the format:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">---------------------<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>Format formato = Format.getPrettyFormat();<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>formato.setTextMode(TextMode.PRESERVE);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>formato.setEscapeStrategy(new EscapeSimbolos());<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>formato.setIgnoreTrAXEscapingPIs(true);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span></span>XMLOutputter outputter = new XMLOutputter(formato);<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">---------------------<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I tried setting setIgnoreTrAXEscapingPIs to false, because I am not sure what this does exactly, but nothing seems to change.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Any ideas?<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:.5in"><br>
<br>
<br>
<u></u><u></u></p>
<pre style="margin-left:.5in">_______________________________________________<u></u><u></u></pre>
<pre style="margin-left:.5in">To control your jdom-interest membership:<u></u><u></u></pre>
<pre style="margin-left:.5in"><a href="http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com" target="_blank">http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com</a><u></u><u></u></pre>
</blockquote>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div></div></div>
</div>
</blockquote></div><br>