EscapeStrategy for in-text html tags not working
SoTaNeZ <[email protected]> Wed, 9 Jan 2013 09:50:06 +0100
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <CAJypjWf_ROGQTcLoi1_HHUMCJaY9tKWdb4NgdC24-VoJLo48-Q@mail.gmail.com> |
--===============0699618202==
Content-Type: multipart/alternative; boundary=047d7b339ceb2b6b5204d2d7262f
--047d7b339ceb2b6b5204d2d7262f
Content-Type: text/plain; charset=ISO-8859-1
Hello.
I have some XML elements which text is not plain, but contains some HTML
tags.
The thing is that when outputting these to an XML file the characters "<"
and ">" are changed into "<" and ">" preventing its correct posterior
HTML processing.
I tried using this EscapeStrategy:
------------------
class EscapeSimbolos implements EscapeStrategy {
public boolean shouldEscape(char car) {
switch (car) {
case '<':
return false;
case '>':
return false;
default:
return false;
}
}
}
------------------
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.
This is the code to set the format:
---------------------
Format formato = Format.getPrettyFormat();
formato.setTextMode(TextMode.PRESERVE);
formato.setEscapeStrategy(new EscapeSimbolos());
formato.setIgnoreTrAXEscapingPIs(true);
XMLOutputter outputter = new XMLOutputter(formato);
---------------------
I tried setting setIgnoreTrAXEscapingPIs to false, because I am not sure
what this does exactly, but nothing seems to change.
Any ideas?
--047d7b339ceb2b6b5204d2d7262f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hello.<div><br><div>I have some XML elements which text is not plain, but c=
ontains some HTML tags.</div><div>The thing is that when outputting these t=
o an XML file the characters "<" and ">" are chan=
ged into "&lt;" and "&gt;" preventing its corre=
ct posterior HTML processing.</div>
<div>I tried using this EscapeStrategy:</div><div><br></div><div>----------=
--------</div><div><div><span class=3D"Apple-tab-span" style=3D"white-space=
:pre"> </span>class EscapeSimbolos implements EscapeStrategy {</div><div><b=
r>
</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </spa=
n>public boolean shouldEscape(char car) {</div><div><span class=3D"Apple-ta=
b-span" style=3D"white-space:pre"> </span>switch (car) {</div><div><span =
class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>case '<=
':</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>re=
turn false;</div><div><span class=3D"Apple-tab-span" style=3D"white-space:p=
re"> </span>case '>':</div><div><span class=3D"Apple-tab-span"=
style=3D"white-space:pre"> </span>return false;</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>def=
ault:</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
</span>return false;</div><div><span class=3D"Apple-tab-span" style=3D"wh=
ite-space:pre"> </span>}</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>}</d=
iv><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>}<=
/div></div><div>------------------</div><div><br></div><div>but with no eff=
ect. The code within the two case statements is never reached, but the meth=
od is executed, so it seems that these characters are converted before the =
EscapeStrategy gets into action, or maybe I am doing something wrong.</div>
<div><br></div><div>This is the code to set the format:</div><div><br></div=
><div>---------------------</div><div><div><span class=3D"Apple-tab-span" s=
tyle=3D"white-space:pre"> </span>Format formato =3D Format.getPrettyFormat(=
);</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>forma=
to.setTextMode(TextMode.PRESERVE);</div><div><span class=3D"Apple-tab-span"=
style=3D"white-space:pre"> </span>formato.setEscapeStrategy(new EscapeSimb=
olos());</div>
<div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>forma=
to.setIgnoreTrAXEscapingPIs(true);</div><div><span class=3D"Apple-tab-span"=
style=3D"white-space:pre"> </span>XMLOutputter outputter =3D new XMLOutput=
ter(formato);</div>
</div><div>---------------------</div><div><br></div><div>I tried setting=
=A0setIgnoreTrAXEscapingPIs to false, because I am not sure what this does =
exactly, but nothing seems to change.</div><div><br></div><div>Any ideas?</=
div>
</div>
--047d7b339ceb2b6b5204d2d7262f--
--===============0699618202==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
--===============0699618202==--