From: F. David Sacerdoti (fds@cs.ucsd.edu)
Date: Wed Nov 01 2000 - 19:01:11 EST
I recently read some excellent posts by Harry Blundell that explain how
to create an internal DTD for an XML document. I would like to summerize
the steps in this post. My code creates a DTD from scratch, but uses
much of Harry's code for creating one from a text buffer.
First, what we are trying to create. Something like this:
<?xml version="1.0"?>
<!DOCTYPE MyRootTag [
<!ENTITY e1 SYSTEM "/tmp/e1.xml">
<!ENTITY e2 SYSTEM "/tmp/e2.xml">
]>
<MyRootTag>
<tag>&e1;</tag>
<tag>&e2;</tag>
</MyRootTag>
-------------------
The code to create it with libxml:
xmlDocPtr doc;
xmlNodePtr tree,root;
xmlDtdPtr dtd;
xmlEntityPtr e;
// Setup XML document and its DTD
doc=xmlNewDoc("1.0");
dtd=xmlNewDtd(doc,"MyRootTag", NULL,NULL);
doc->intSubset=dtd;
dtd->parent=doc;
dtd->doc=doc;
doc->children=(xmlNodePtr) dtd;
root=xmlNewDocNode(doc,NULL,"MyRootTag",NULL);
xmlDocSetRootElement(doc,root);
e=xmlAddDtdEntity(doc, "e1" XML_EXTERNAL_GENERAL_PARSED_ENTITY, NULL,
"/tmp/e1.txt","e1");
// Build the rest of the tree with the 'root' xmlNodePtr.
xmlDumpFile(FILE, doc)
--------------
I hope this helps others who are looking to create DTDs for their
documents. I am not sure this is the correct way to do it, but it seems
to work for me.
Dave
---- Message from the list xml@rpmfind.net Archived at : http://xmlsoft.org/messages/ to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
This archive was generated by hypermail 2b29 : Wed Nov 01 2000 - 20:43:36 EST