logo       

Re: Re: How can I insert 'raw' (X|XHT|HT)ML into my DOM?: msg#00037

java.enhydra.xmlc

Subject: Re: Re: How can I insert 'raw' (X|XHT|HT)ML into my DOM?

On Thursday 16 January 2003 21:53, dcorbin@xxxxxxxxxxxxxx wrote:
[ ... snip .. ]

> > Hmmm. I'd probably go the clean and safe way and build a DOM out of it
> > - especially if you don't want to be locked into (X)HTML for output
> > but want to produce different output formats as well (say, WML or
> > cHTML for wireless, or DocBook for printing). After all, if your
> > snippets already are in XHTML format, you can simply run them through
> > a standard XML parser - no need to write your own.
>
> Well, the snippets are XHTML *fragments*, not valid documents. I don't
> know what the parsing implications of that are.


If the snippets themselves are wellformed (i.e., don't have
misbalanced/missing tags), the worst case would be that you've got to slap on
an XML header line (<?xml version="1.0"?>) and (If you want to validate) an
appropriate doctype line to produce a complete document.

E.g., if you have a snippet like this:

<p>Here is some <i>Text</i> with <b>markup</b></p>

you'd simply prepend a nearly string (the XML header and doctype) - the only
difference to the "standard" XHTML doctype line is that you don't give "html"
as toplevel element, but whatever happens to be the toplevel element of your
snippet (in the example, "p"). What you get is something like this:

<?xml version="1.0"?>
<!DOCTYPE p PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<p>Here is some <i>Text</i> with <b>markup</b></p>

And this "mini-document" runs through every XML parser - even with validation.

If you don't want to go to the trouble of figuring out the name of the
toplevel tag in a snippet before parsing (if you actually allow more than
one), you can always create a customized DTD by adding a <fragment> (or
whatever) tag to the original XHTML DTD that allows all the toplevel tags
that can occur in your snippets (and you can strip down the original DTD to
only allow safe tags).

This leaves you with having to prepend a constant header (XML header line,
doctype line and the openeing <fragment> tag) and append a constant trailer
(the closing </fragment> tag) to the snippets before you hand them off to the
parser.

Bye,

Richard
--
Richard Kunze

[ t]ivano Software, Bahnhofstr. 18, 63263 Neu-Isenburg
Tel.: +49 6102 80 99 07 - 0, Fax.: +49 6102 80 99 07 - 1
http://www.tivano.de, kunze@xxxxxxxxx


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise