Re: [xml] xmlNewTextWriterTree, writerTree
- From: David Wimsey <dwimsey rtsz com>
- To: Kresimir Karamazen <k karamazen trinite nl>
- Cc: xml gnome org
- Subject: Re: [xml] xmlNewTextWriterTree, writerTree
- Date: Mon, 27 Oct 2008 06:21:21 -0400
You are creating two root elements, which is not valid XML. You'll need
to do something like:
The resulting XML file will look something like:
void
testXmlwriterTree(const char *file)
{
xmlTextWriterPtr writer;
xmlDocPtr doc;
xmlNodePtr node;
// tested on the version 2.6.26
doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
node = xmlNewDocNode(doc, NULL, BAD_CAST "Alivemessage", NULL);
xmlDocSetRootElement(doc, node);
writer = xmlNewTextWriterTree(doc, node, 0);
xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
xmlTextWriterStartElement(writer, BAD_CASE "DocumentRoot"); // Starts a toplevel element named Document
root
xmlTextWriterStartElement(writer, BAD_CAST "HEADER"); // this goes inside DocumentRoot
xmlTextWriterEndElement(writer);
xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES"); // this goes inside DocumentRoot, but after
HEADER
xmlTextWriterEndElement(writer);
xmlTextWriterEndElement(writer); // ends DocumentRoot
xmlTextWriterEndDocument(writer);
xmlFreeTextWriter(writer);
xmlSaveFileEnc(file, doc, MY_ENCODING);
xmlFreeDoc(doc);
}
The resulting XML file will look something like:
<?xml version="1.0" encoding="utf-8" ?><DocumentRoot><HEADER/><ENTRIES/></DocumentRoot>
Kresimir Karamazen wrote:
I have modified an example from the libxml2 documentation to use
xmlNewTextWriterTree for writing to the tree
but it doesn't work unless I comment out 'critical':
void
testXmlwriterTree(const char *file)
{
xmlTextWriterPtr writer;
xmlDocPtr doc;
xmlNodePtr node;
// tested on the version 2.6.26
doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
node = xmlNewDocNode(doc, NULL, BAD_CAST "Alivemessage", NULL);
xmlDocSetRootElement(doc, node);
writer = xmlNewTextWriterTree(doc, node, 0);
xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
xmlTextWriterEndElement(writer);
/* begin critical*/
xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES");
xmlTextWriterEndElement(writer);
/*
Entity: line 2: parser error : Extra content at the end of the
document
<HEADER/><ENTRIES/>
*/
/* end critical*/
xmlTextWriterEndDocument(writer);
xmlFreeTextWriter(writer);
xmlSaveFileEnc(file, doc, MY_ENCODING);
xmlFreeDoc(doc);
}
________________________________________________________________________
K.Karamazen
Trinità Automatisering B.V.
Post-adres: Postbus 189, 1420 AD Uithoorn
Bezoek-adres: J.N. Wagenaarweg 6, 1422 AK Uithoorn
Tel. : 0297 382460
Fax : 0297 273049
Email: kk trinite nl
Website: www.trinite.nl
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]