[
Lists Home |
Date Index |
Thread Index
]
If you are asking if you can supply the DTD for a parser to use at runtime, then consult the
parser documentation. You may not even need to change any text, but just provide a
CATALOG file (to remap the declaration) or supply a command-line parameter.
If you are asking for an algoithm to let you safely insert a DOCTYPE declaration
on the fly yourself, following is a quick stab. It should be good enough if you are just
serializing elements. Start by assuming there is already no DOCTYPE declaration and
that any PIs or comments don't have < in them.
* Search for the first "<" not followed by "!", "?" or whitespace.
* If the next character is "/" then that is an end-tag and your document is not well-formed
* Store the string on the current line until the first white space or ">" or "/" character.
That is the first elements name.
* Insert your DOCTYPE declaration with that string, immediately before that
first "<" (*not* at the start of the file: this way you preserve any XML headers
and stylesheet PIs)
* Make each of the 4 examples below into XML documents, and test your routine
on each of them. They each test some common edge cases.
---
<x/>
-----
<x></x >
-----
<?xml version="1.0" ?>
<!-- a comment -->
<a
/>
------
<abcdef:ghij xmlns:ghjij="klmno://pqrst/uvw.xyz " >
<x />
</abcdef:ghij>
-------
Cheers
Rick Jelliffe
----- Original Message -----
From: "Rupa Kulkarni" <rupali@assetlink.com>
To: <xml-dev@lists.xml.org>
Sent: Wednesday, April 24, 2002 7:49 PM
Subject: [xml-dev] DOCTYPE
Hi
Can I generate the <!DOCTYPE xxxx SYSTEM "xx.dtd"> instruction at run time ???
Rupa
- References:
- DOCTYPE
- From: "Rupa Kulkarni" <rupali@assetlink.com>
|