[jdom-interest] Problems with '<' and '>' in element.addContent()
Ken Rune Helland
kenh at csc.no
Wed Jan 2 04:04:04 PST 2002
> Hi
>
> I have a problem when I try to add content included the signs "<"
> and ">"to an element. I write:
> element.addContent("<HTML><HEAD></HEAD><BODY>");
The characters '<' and '>' are xml characters and jdom asumes when these
characters is in a child content that these characters is to be escaped as
not to be read as xml characters ( '<' is the escape for '<' and '>'
for '>').
To get what you need i jdom you must make a 'HTML' element and add a 'HEAD'
element and a 'BODY' element as children to the 'HTML' element.
Content inside the body must then be added as children to the 'BODY'
element.
example:
Element root = new Element("HTML");
Document doc = new Document( root );
root.addContent(new Element("HEAD");
Element body = new Element("BODY");
root addContent(body);
Element header1 = new Element("H1");
body.addContent(header1);
header1.addContent("text 1");
body.addContent("text 2");
When outputting this document you shoud get someting like
<HTML>
<HEAD/>
<BODY>
<H1>text 1</H1>
text 2
</BODY>
</HTML>
But im not certain JDOM is good for html as valid html is not nesesarily
valid xml.
KenR
More information about the jdom-interest
mailing list