[xml] use of xmlTextWriterWriteDTD?



I'm writing a small utility to convert some configuration files to XML
using the xmlWriter API  Just about the only info I can find is the 
example from the site (http://xmlsoft.org/examples/index.html#xmlWriter).  
I managed to get my utility working rather quickly based on what I learned 
from that.

I'm trying to add writing the DOCTYPE declaration to the beginning of the 
XML files that are created, but I'm getting this error:

xmlTextWriterStartDTD : DTD allowed only in prolog!

and the DOCTYPE is not written to the file.

Basically, what I'm doing is this (error checking removed for simplicity):

...
writer = xmlNewTextWriterDoc(&doc, 0);
xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
xmlTextWriterWriteDTD(writer, (xmlChar *)"fieldconf", NULL,
                        (xmlChar *)"/devel/dtds/mfield.dtd", NULL);
xmlTextWriterStartElement(writer, (xmlChar *)"fieldconf");
...

Digging through the code for libxml, it looks like both 
xmlTextWriterStartDocument and xmlTextWriterStartDTD check that they are 
the first part of the document.

I tried removing the StartDocument call just to see if it would get rid of 
the StartDTD error (expecting other problems), but I got the exact same 
error again.

Is there a proper way to do this that I am missing?  Or will I have to add 
the DOCTYPE to all the files by hand?  (Something I would much rather 
avoid)

I'm also not 100% sure I'm calling the WriteDTD func properly to write the 
following DOCTYPE line (I think I am, but the lack of docs leaves me a 
little uncertain):

<!DOCTYPE "fieldconf" SYSTEM "/devel/dtds/mfield.dtd">

Thanks

-- 
trey




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