[xml] XML newbie question


I am trying to generate a XML file that corresponds to a DTD and which looks like this:

<!DOCTYPE cfgdata SYSTEM "1ca.dtd">
<!-- Host data -->
      <procname>Sparc sun4u</procname>

My C code is as follows:
   xmlresp = xmlNewDoc ("1.0");

   node = xmlNewDocNode(xmlresp, NULL, "config", NULL);
   xmlCreateIntSubset(xmlresp, "config", NULL, "1ca.dtd");
   xmlresp->children = node;

   hchild = xmlNewChild (node, NULL, "host", NULL);
   hchild1 = xmlNewChild (hchild, NULL, "hname", NULL);
   hchild2 = xmlNewChild (hchild, NULL, "proc", NULL);

   xmlSetProp(hchild1, "hcmnd1", hostdata->command1);
   xmlSetProp(hchild1, "hostname", hostdata->hname);
  xmlSetProp(hchild2, "hcmnd2", hostdata->command2);
  xmlSetProp(hchild2, "procname", hostdata->procname);

  When I compile this program and run it, the xml generated is as follows:

<?xml version="1.0"?>
<config><host><hname hcmnd1="uname" hostname="solhost" osname="Solaris" osver="10"
/><proc hcmnd2="psrinfo" procname="sparcv9"/></host></config>

My question is this:

Why is my opening tag wrong and my closing tag missing?
Why do I see
<hname hcmnd1="uname" hostname="solhost" ... />
instead of
<hname> hcmnd1="uname" hostname="solhost" ...</hname>



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