Hi everybody,
I'm new in xerces and I get some trouble just to write a basic XML file !!!
I try to create a DOM document from scratch and then to write it into a file
on the disk, here is the code:
int errorCode = 0;
if(!appendEventsXML && impl != 0) {
try {
//XMLFormatTarget *myFormTarget = new
LocalFileFormatTarget(X("res.xml"));
DOMWriter *theSerializer =
((DOMImplementationLS*)impl)->createDOMWriter();
DOMDocument* doc = impl->createDocument(
0,
// root element namespace URI.
X("company"), // root element name
0); // document type object
(DTD).
DOMElement* rootElem = doc->getDocumentElement();
DOMElement* prodElem =
doc->createElement(X("product"));
rootElem->appendChild(prodElem);
DOMText* prodDataVal =
doc->createTextNode(X("Xerces-C"));
prodElem->appendChild(prodDataVal);
DOMElement* catElem =
doc->createElement(X("category"));
rootElem->appendChild(catElem);
catElem->setAttribute(X("idea"), X("great"));
DOMText* catDataVal = doc->createTextNode(X("XML
Parsing Tools"));
catElem->appendChild(catDataVal);
DOMElement* devByElem =
doc->createElement(X("developedBy"));
rootElem->appendChild(devByElem);
DOMText* devByDataVal =
doc->createTextNode(X("Apache Software
Foundation"));
devByElem->appendChild(devByDataVal);
//
// Now count the number of elements in the above DOM
tree.
//
unsigned int elementCount =
doc->getElementsByTagName(X("*"))->getLength();
XERCES_STD_QUALIFIER cout << "The tree just created
contains: " <<
elementCount
<< " elements." << XERCES_STD_QUALIFIER endl;
XMLFormatTarget *myFormatTarget = new
LocalFileFormatTarget("myXMLFile.xml");
theSerializer->writeNode(myFormatTarget, *prodElem);
}
catch (const OutOfMemoryException&)
{
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" <<
XERCES_STD_QUALIFIER endl;
errorCode = 5;
}
catch (const DOMException& e)
{
XERCES_STD_QUALIFIER cerr << "DOMException code is: "
<< e.code <<
XERCES_STD_QUALIFIER endl;
errorCode = 2;
}
catch (...)
{
XERCES_STD_QUALIFIER cerr << "An error occurred
creating the document" <<
XERCES_STD_QUALIFIER endl;
errorCode = 3;
}
} else {
XERCES_STD_QUALIFIER cerr << "Requested implementation is not
supported"
<< XERCES_STD_QUALIFIER endl;
errorCode = 4;
}
What am I doing wrong ?? the file is created but nothing is inside !!!
thanks for your help
--
View this message in context:
http://www.nabble.com/DOMWriter-tf4065159.html#a11550772
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]