[jdom-interest] Problems with '<' and '>' in element.addConte nt()

Mani Doraisamy MDoraisamy at SELECTICA.com
Wed Jan 2 04:44:39 PST 2002

"But im not certain JDOM is good for html as valid html is not nesesarily 
valid xml."

yes. i accept that. But is there a better way of converting JDOM to HTML ? 
I am not convinced with converting JDOM to streamsource and coverting into 
HTML using XSLT. how much is the performance loss ?

Is there a native XSLT for JDOM available ?


-----Original Message-----
From: Ken Rune Helland [mailto:kenh at csc.no]
Sent: Wednesday, January 02, 2002 5:34 PM
To: ann_b15 at hotmail.com
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] Problems with '<' and '>' in

> 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 ( '&lt;' is the escape for '<' and '&gt;' 
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 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");

header1.addContent("text 1");

body.addContent("text 2");

When outputting this document you shoud get someting like

     <H1>text 1</H1>
     text 2

But im not certain JDOM is good for html as valid html is not nesesarily 
valid xml.


To control your jdom-interest membership:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020102/27ca2511/attachment.htm

More information about the jdom-interest mailing list