Re: [xml] Combining two xml files.



On 02/08/04 08:13, Manish Padmajan wrote:
Hi All,
I am trying to combine 2 xml files into 1 using libxml library.
This is what I have done.
writer = xmlNewTextWriterFilename(file,0);
rc = xmlTextWriterStartElement(writer,BAD_CAST "root");
doc1 = xmlParseFile(file1);
cur = xmlDocGetRootElement(doc1);
rc = xmlTextWriterStartElement(writer,BAD_CAST "xnlFile1");
print_element(cur,doc1,writer,0); //for parsing through the xml file and
writing node name and value. This function is called recursively.
rc = xmlTextWriterEndElement(writer);
doc2 = xmlParseFile(file2);
cur = xmlDocGetRootElement(doc2);
rc = xmlTextWriterStartElement(writer,BAD_CAST "xnlFile2");
print_element(cur,doc2,writer,0);//for parsing through the xml file and
writing node name and value. This function is called recursively.
rc = xmlTextWriterEndElement(writer);
xmlFreeDoc(doc1);
xmlFreeDoc(doc2);
rc = xmlTextWriterEndElement(writer);
xmlFreeTextWriter(writer);
xmlCleanupParser();
When we see the contents of the final xml file, the 'root' is closed even
before the contents of the second file is copied into the final xml file.
Hence the xml file reports an error. Is there anything wrong that I am doing. I even tried calling
xmlCleanupParser() after parsing each xml file. But it had no effect.
If only one xml file is parsed and written into the final xml file, no
errors are reported.
Any hints in this direction will be really helpful.

How about using XInclude?

Ciao,
Igor



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