[xml] DTDs and null SystemID/ExternalID ?



Setup for the question: it appears that there are 3 basic DOCTYPES for an xml document:

1:
<!DOCTYPE root_name SYSTEM "local_path_to_dtd">
<
...
(xml content)
...


2:
<!DOCTYPE root_name PUBLIC "url_to_dtd">
<
...
(xml content)
...


3:
<!DOCTYPE root_name [
...
(element definitions etc)
...
]>
<
...
(xml content)
...



I'm trying to do the 3rd one, where the dtd is self-contained within the xml file. I am doing it in memory, using xmlParserInputBufferCreate etc. I create a doc using xmlNewDoc, then the dtd from the buffer using xmlIOParseDTD, and then blow it out to disk with xmlSaveFormatFile. Works like a champ, except that...

I've boxed myself into a corner. Snooping the libxml2 source (xmlsave.c, xmlDtdDumpOutput), I see that I can create the 3rd type only if SystemID and ExternalID are NULL. But this is directly at odds with xmlIOParseDTD, which ultimately allocates both and fills them in with "none".

You can't naively can't set them to NULL after the fact, because you will die in xmlFreeDoc.

Is there a way to create the dtd in memory so that both SystemID and ExternalID are NULL, giving me DOCTYPE #3? Or am I out in left field here? (I'm working my way through learning this stuff bit by bit, and frankly don't know any better...)


Stefan Jeglinski



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]