You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "jerome.mariette" <je...@mbari.org> on 2007/07/21 00:29:17 UTC
DOMDocument::importNode()
Hi everyone,
I'm trying to import an XML file parsed with XercesDOMParser into my main
DOMDocument as following:
/*#####################################################
*Parse the file to add
*/
itsParser = new XercesDOMParser();
itsParser->setDoNamespaces(true);
itsParser->setDoSchema(true);
itsParser->setValidationScheme(XercesDOMParser::Val_Always);
itsParser->setExternalNoNamespaceSchemaLocation("mySchema.sxd");
// Instancie un ErrorHandler et le lie au parser
itsErrHandler = new ErrReporter();
itsParser->setErrorHandler(itsErrHandler);
/* Create the document */
DOMDocument* domdoc = impl->createDocument(NULL, NULL, NULL);
// Parse le fichier XML et récupère le temps mis pour le parsing
try {
itsParser->resetDocumentPool();
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
itsParser->parse("myXML.xml");
if (itsParser->getErrorCount() == 0) {
domdoc = itsParser->getDocument();
}
else {
LINFO("Error when attempting to parse the XML file ");
}
}
// Exception XML
catch (const XMLException& err) {
LINFO("Erreur XML pendant le parsing du fichier : %s ", inputXML);
}
// Exception DOM
catch (const DOMException& err) {
const unsigned int maxChars = 2047;
XMLCh errText[maxChars + 1];
LINFO("Erreur DOM pendant le parsing du fichier : %s \n", inputXML);
if (DOMImplementation::loadDOMExceptionMsg(err.code, errText, maxChars))
LFATAL("Exception DOM : %s ", XMLString::transcode(errText));
} catch (...) {
LINFO("Erreur inattendue durant le parsing du fichier : %s", inputXML);
}
/*#####################################################
* End Parsing */
/*#####################################################
* add it to an other DOMDocument
*/
XMLCh* rootvalue = XMLString::transcode("MainRoot");
DOMDocument* mainDOM = impl->createDocument(NULL, rootvalue, NULL);
XMLString::release(&rootvalue);
DOMNode* domnode = domdoc->getDocumentElement();
DOMElement* root = itsXMLdoc->getDocumentElement();
root->importNode(domnode, true);
/*#####################################################
* End adding XML */
What am I doing wrong ?
thanks so much for all your help,
Jerome
--
View this message in context: http://www.nabble.com/DOMDocument%3A%3AimportNode%28%29-tf4119877.html#a11717007
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
Re: DOMDocument::importNode()
Posted by "jerome.mariette" <je...@mbari.org>.
Thank you so much for all your help,
it's working as well :)
Alberto Massari wrote:
>
> Hi Jerome,
>
> At 15.29 20/07/2007 -0700, jerome.mariette wrote:
>
>>Hi everyone,
>>I'm trying to import an XML file parsed with XercesDOMParser into my main
>>DOMDocument as following:
>>[...]
>> /*#####################################################
>> * add it to an other DOMDocument
>> */
>> XMLCh* rootvalue = XMLString::transcode("MainRoot");
>> DOMDocument* mainDOM = impl->createDocument(NULL, rootvalue,
>> NULL);
>> XMLString::release(&rootvalue);
>> DOMNode* domnode = domdoc->getDocumentElement();
>> DOMElement* root = itsXMLdoc->getDocumentElement();
>> root->importNode(domnode, true);
>> /*#####################################################
>> * End adding XML */
>>
>
> importNode will simply clone the source node to make it usable inside
> the new document, but it will not add it to the DOM tree; you need to
> do first import it, then append to an existing node.
> It's not clear from your example where you want to add it (you create
> a new mainDOM document, but then you don't use it; you invoke
> importNode on the root element of itsXMLdoc, but the method is
> defined on DOMDocument, not on DOMElement), so I'll try to guess:
>
> DOMNode* domnode = domdoc->getDocumentElement();
> DOMNode* newRoot=mainDOM->importNode(domnode, true);
> mainDOM->getDocumentElement()->appendChild(newRoot);
>
> Alberto
>
>
>>What am I doing wrong ?
>>thanks so much for all your help,
>>Jerome
>>--
>>View this message in context:
>>http://www.nabble.com/DOMDocument%3A%3AimportNode%28%29-tf4119877.html#a11717007
>>Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
>>For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/DOMDocument%3A%3AimportNode%28%29-tf4119877.html#a11750656
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
Re: DOMDocument::importNode()
Posted by Alberto Massari <am...@datadirect.com>.
Hi Jerome,
At 15.29 20/07/2007 -0700, jerome.mariette wrote:
>Hi everyone,
>I'm trying to import an XML file parsed with XercesDOMParser into my main
>DOMDocument as following:
>[...]
> /*#####################################################
> * add it to an other DOMDocument
> */
> XMLCh* rootvalue = XMLString::transcode("MainRoot");
> DOMDocument* mainDOM = impl->createDocument(NULL, rootvalue, NULL);
> XMLString::release(&rootvalue);
> DOMNode* domnode = domdoc->getDocumentElement();
> DOMElement* root = itsXMLdoc->getDocumentElement();
> root->importNode(domnode, true);
> /*#####################################################
> * End adding XML */
>
importNode will simply clone the source node to make it usable inside
the new document, but it will not add it to the DOM tree; you need to
do first import it, then append to an existing node.
It's not clear from your example where you want to add it (you create
a new mainDOM document, but then you don't use it; you invoke
importNode on the root element of itsXMLdoc, but the method is
defined on DOMDocument, not on DOMElement), so I'll try to guess:
DOMNode* domnode = domdoc->getDocumentElement();
DOMNode* newRoot=mainDOM->importNode(domnode, true);
mainDOM->getDocumentElement()->appendChild(newRoot);
Alberto
>What am I doing wrong ?
>thanks so much for all your help,
>Jerome
>--
>View this message in context:
>http://www.nabble.com/DOMDocument%3A%3AimportNode%28%29-tf4119877.html#a11717007
>Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
>For additional commands, e-mail: c-dev-help@xerces.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org