You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by 장승필 <sp...@pusan.ac.kr> on 2002/06/12 15:56:24 UTC

Error in XalanDocument::importNode()

Hi, all.
I question 'How to rebuild Xalan DOM' in previous mail.
But, no answer.. -_-a
I know one solution, using XalanDocument::importNode().
So my code is corrected like that ;

void main()
{
    DOMParser* parser = new DOMParser;
    parser->parse(filename);
 
    DOM_Document dom_doc = parser->getDocument() ;
    XercesDOMSupport*  support = new XercesDOMSupport() ;
    XercesDOMSupport  theDOMSupport ;
    XercesParserLiaison  theLiaison(theDOMSupport) ;
    XalanDocument*  doc = theLiaison.createDocument(dom_doc) ;

    XalanElement* root = doc->getDocumentElement() ;
    XalanElement* element1 =doc->createElement(XalanDOMString("Test1")) ;
    element1->appendChild(doc->createText(XalanDOMString("Good")) ;
    root->appendChild(element1) ;    // Update OK!

    /* I use XPath of Xalan for doing something. */
        ....

    XalanElement* element2 = doc->createElement(XalandOMString("Test2")) ;
    element2->appendChild(doc->createText(XalanDOMString("Error")) ;
    root->appendChild(element2) ;    // NOT update

    XalanDocument*  doc2 = theLiaison.createDocument(dom_doc) ;
    XalanNode* imported = doc->importNode(doc2->getDocumentElement(), true) ; // Unhandled exception
   root->getParentNode()->replaceChild(imported, root) ;
    root = (XalanElement*) imported ;

    XalanStdOutputStream   theStream(cout);
    XalanOutputStreamPrintWriter thePrintWriter(theStream);
    FormatterToXML   theFormatter(thePrintWriter);
    FormatterTreeWalker  theWalker(theFormatter);
    theFormatter.setShouldWriteXMLHeader(false);
    theFormatter.startDocument();
    theWalker.traverseSubtree(root);
    theFormatter.endDocument() ;
}

But, Unhandled exception occurred in 'doc->importNode(doc2->getDocumentElement(), true)'
Why?
And is any other solution in 'How to rebuild Xalan DOM?'
Thanks!