Re: Write DTD to XML File [message #70433] |
Thu, 15 April 2010 09:47 |
Karl[1]
Messages: 79 Registered: October 2005
|
Member |
|
|
On Apr 15, 5:31 am, Dr Steve <Dr_St...@aanet.com.au> wrote:
> Hi All,
>
> I'm using the IDL XML objects for reading and writing XML parameter
> files for my applications. However, I can't see how to write a DTD to
> my XML file. If I read in an XML file, with a DTD, using the LOAD
> method for the IDLffXMLDOMDocument class, and then write it back out
> using the SAVE method of the same class, the DTD is preserved. Also if
> I delete the DocumentType Node, and then write out the file, the DTD
> is no longer written. So the DTD is stored within DocumentType node.
> However, none of the methods to the IDLffXMLDOMDocumentType seem to
> give me access to the DTD. Anyone dealt with this before?
>
> I actually use the SAX parser for reading my XML, and I believe it
> would give me access to the DTD (via the startDTD/endDTD methods), but
> this still doesn't allow me to write the DTD to the XML file.
>
> Thanks,
>
> Stephen
If you are creating a new XML file from scratch and you want it to
have a DTD, you could try:
doctext = '<?xml version="1.0" encoding="UTF-8"?><mydoc><!DOCTYPE foo
SYSTEM "bar.dtd"></mydoc>'
o = obj_new("IDLffXMLDOMDocument", STRING=doctext)
o->Save, filename="blah"
o = obj_new("IDLffXMLDOMDocument", filename="blah")
create the rest of the nodes for the XML content.
You should be able to read the DTD data with the DocumentType
GetEntities, GetName, and GetNotations methods, right?
It looks like this class can't write DTD data to the object; I don't
know why.
If you wanted to add a DTD to an XML document that does not have a
DTD, you can still use a approach similar to this. Create a new doc
with just the DTD via a string, as above, and then open the original
doc in another object. I think that there are methods to let you copy
the nodes over.
Karl
|
|
|