christian.eickhoff
Usenet Archive
- Joined
- Sep 18, 2006
- Messages
- 11
- Reaction score
- 0
Hello Everyone,
currently I am implementing a solution to write individually created XML data to a file using c++ and Xerces-c 2.7.0 library. Therefore I am making use of DOMWriter class which allows me to write the according DOM tree to a given location using LocalFileFormatTarget. Everything works fine except that I cant define and set a certain XML declaration. The tutorial seems to provide an easy way to do this by applying the setEncoding, setVersion or setStandalone functions to the according DOMDocument. But even after setting those parameters as well as enabling the fgDOMXMLDeclaration feature of the DOMWriter nothing is written except one empty line at the beginning of the document. What am I doing wrong???
The according code snippet is given below:
const XMLCh gLS = { chLatin_L, chLatin_S, chNull };
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(gLS);
DOMWriter* theSerializer = ((DOMImplementationLS*)impl)-
DOMDocument* doc;
doc = impl->createDocument(
0, // root element namespaceURI.
XMLString::transcode("rootnode"), // root element name
0); // document type object(DTD).
doc->setEncoding(XMLString::transcode("UTF-8"));
doc->setVersion(XMLString::transcode("1.0"));
DOMNode* node = XMLwalker->getRoot; //Set Walker to Root node of the document XMLFormatTarget *myFormTarget; myFormTarget = new LocalFileFormatTarget(written_XML_name.c_str); //output to file try{ theSerializer->writeNode(myFormTarget, *node); } catch.....
Any Help is appreciated as for my purposes the integration of the xml declaration is compulsory!
Best regards,
Christian Eickhoff
currently I am implementing a solution to write individually created XML data to a file using c++ and Xerces-c 2.7.0 library. Therefore I am making use of DOMWriter class which allows me to write the according DOM tree to a given location using LocalFileFormatTarget. Everything works fine except that I cant define and set a certain XML declaration. The tutorial seems to provide an easy way to do this by applying the setEncoding, setVersion or setStandalone functions to the according DOMDocument. But even after setting those parameters as well as enabling the fgDOMXMLDeclaration feature of the DOMWriter nothing is written except one empty line at the beginning of the document. What am I doing wrong???
The according code snippet is given below:
const XMLCh gLS = { chLatin_L, chLatin_S, chNull };
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(gLS);
DOMWriter* theSerializer = ((DOMImplementationLS*)impl)-
if (theSerializer->canSetFeature(XMLUni::fgDOMXMLDeclaration,true)) theSerializer->setFeature(XMLUni::fgDOMXMLDeclaration, true);createDOMWriter;
DOMDocument* doc;
doc = impl->createDocument(
0, // root element namespaceURI.
XMLString::transcode("rootnode"), // root element name
0); // document type object(DTD).
doc->setEncoding(XMLString::transcode("UTF-8"));
doc->setVersion(XMLString::transcode("1.0"));
DOMNode* node = XMLwalker->getRoot; //Set Walker to Root node of the document XMLFormatTarget *myFormTarget; myFormTarget = new LocalFileFormatTarget(written_XML_name.c_str); //output to file try{ theSerializer->writeNode(myFormTarget, *node); } catch.....
Any Help is appreciated as for my purposes the integration of the xml declaration is compulsory!
Best regards,
Christian Eickhoff