[xml] XML for config files
- From: Jason Valenzuela <jvalenzuela dspfl com>
- To: xml gnome org
- Subject: [xml] XML for config files
- Date: Fri, 18 May 2007 19:49:59 -0400
Disclaimer--I'm quite new to XML and libxml so please feel free to let
me know if the following approach is any combination of wrong, stupid or
just plain crazy.
I'm writing a little app and XML seems to be a good choice to use for
the configuration file syntax. I have a mind to first validate the
configuration file against a DTD compiled into the program. I first
created a config file with the DTD within it just to make sure I got the
DTD and everything correct to begin with. So far so good. I now removed
the DTD and placed it into a char array in my program. Here are the
basic steps I'm going through:
1. xmlReadFile() - Read in the configuration file.
2. xmlReadMemory() - Read in the DTD from a char[].
3. xmlNewDtd() - Create a new DtdPtr from 2.
4. xmlNewValidCtxt() - Not quite clear about this, but I need it.
5. xmlValidateDtd() - Using the doc file from 1 and the DtdPtr from 3.
6. Various xmlFree'ing when I'm done.
When I first moved the DTD into the program, it seems that xmlReadMemory
was unhappy until I put an empty root element after the DTD, as the DTD
itself had only <?xml verion=blah encoding=foo?> followed by the DTD
proper. The empty root element I added was not defined by the DTD, but
it seemed to make xmlReadMemory happy. Is adding a bogus root element to
a DTD-only file the right thing to do?
Of course now it won't validate. For every element, libxml spits out a
validity error : No declaration for element <element name>.
I don't quite know what is appropriate for the ExternalID and SystemID
arguments to xmlNewDtd, or if I should even care in this application.
Are there applications where one should use the reader instead of the
parser? For example I'm currently using the parser's xmlReadMemory
instead of xmlReaderForMemory only because xmlNewDtd and xmlValidateDtd
want doc pointers. Beyond that I'm not sure about the difference between
the two interfaces.
That wraps up my initial newbie questions, thanks in advance for any help,
Jason Valenzuela
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]