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 David N Bertoni/Cambridge/IBM <da...@us.ibm.com> on 2002/03/04 19:51:28 UTC

RE: removeChild of xalanNode (found by xpath) from parsed xml file throw XalanDomExeption

When you modify the Xerces DOM, you must rebuild the Xalan nodes that
bridge their DOM to ours.  There is a usage pattern that describes how to
parse a document using Xerces, then wrap the Xerces DOM in ours.  You need
to destroy the original wrapper, then create a new one to see the changes.
Of course, if some of the nodes in your node list were the ones you
removed, then of course you'll see them in the output.  Removing the nodes
from the document does not destroy them, nor does it remove them from the
list.

There are also many previous discussions in the mail archives on this
topic.  Make sure you search the Xalan Developer list, since that's been
around much longer than the Xalan-C user list:

   http://marc.theaimsgroup.com/?l=xalan-dev&r=1&w=2

Here's a link to the usage pattern for the DOM:

   http://xml.apache.org/xalan-c/usagepatterns.html#dom

You can also serialize the Xerces DOM_Document instance, instead of
rebuilding the bridge and running our serializer.  There's been much talk
about a serializer on the Xerces-C mailing list.  You might want to
subscribe, or search the archives.

I'm still not clear on what your application is trying to do.  It would
better for you to describe your _entire_ application model, instead of just
portions of it.  Otherwise, it's pretty difficult to figure out the best
way for you to proceed.

Dave



                                                                                                              
                      "Tankel, Ifat"                                                                          
                      <Ifat_Tankel@ico         To:      xalan-c-users@xml.apache.org                          
                      mverse.com>              cc:      (bcc: David N Bertoni/Cambridge/IBM)                  
                                               Subject: RE: removeChild of xalanNode (found by xpath) from    
                      03/04/2002 05:09         parsed xml fil e throw XalanDomExeption                        
                      AM                                                                                      
                                                                                                              
                                                                                                              



Hi, Dave
I replaced the XalanSourceTreePraserLiaison with the XercesParserLiason and
then I do succeeded in deleting the Node.

Now I wanted to see that the XalanDocument * returned by the
XercesParserLiaison::createDocument  was update (the nodes where removed )
so I did the same as in the serialize example
             I created XalanStdOutputStream
,XalanOutputStreamPrinterWriter,
FormatterToXML, and FormaterTreeWalker
             I called FormatterToXML::startDocument
             I created nodeList using the evaluator
             I used the FormatterTreeWalker::traverseSubtree
             and Finally I I called FormatterToXML::endDocument

What amazed me was that I saw the Nodes that I removed already on the
screen?
then I tried to remove the same Node that were already removed again and I
got an exception that they do not exist.
so what's going on?
I thought that may be the nodes are only marked as been deleted am I right?

I need to send the updated document to another application as a stream
buffer Where can I find an example for that?
I scanned the archive and I did not found something that can help me.

Regards
Ifat




-----Original Message-----
From: David N Bertoni/Cambridge/IBM [mailto:david_n_bertoni@us.ibm.com]
Sent: Tuesday, February 26, 2002 11:54 PM
To: xalan-c-users@xml.apache.org
Subject: Re: removeChild of xalanNode (found by xpath) from parsed xml file
throw XalanDomExeption



Ifat,

Please try to limit the size of your post to something more reasonable.
This is quite a bit of code, and a smaller example is much easer to
understand.

> void myDom::removeNode(string xpath){
>   cout <<"-------------removeNode start " <<endl;
>   try{
>     XalanNode * xpathNode=this->getNode(_evaluatorI,xpath);
>     cout << "parent node type=" <<
> xpathNode->getParentNode()->getNodeType()<< endl;
>     cout << "parent node name=" <<
> xpathNode->getParentNode()->getNodeName()<< endl;
>     (xpathNode->getParentNode())->removeChild(xpathNode);
>     cout << "remove child finished" <<endl;
>     cout <<"-------------removeNode finished " <<endl;
>   }
>   catch (const XalanDOMException & e) {
>     cout << "XalanDomExeption was thrown code=" << e.getExceptionCode()
> <<endl
>             << e.getMessage().c_str() <<endl
>             << e.getType().c_str() <<endl
>             << e.getLineNumber <<endl
>             << e.getColumnNumber() <<endl;
>     throw;
>   }
>   catch(...){
>     cout << "Exeption was thrown" <<endl;
>     throw;
>   }
> }

The tree that Xalan builds is not mutable.  If you check the error code in
the XalanDOMException instance, you'll see that it's
NO_MODIFICATION_ALLOWED_ERR.  If you want to do this sort of thing, you'll
need to use the Xerces DOM and our wrapper around their DOM.  There is more
information in the documentation and you'll find lots of discussion about
this in the mail archives.

>   XalanDocument * _xalanDocument;//not been deleted at the distructor
since
> ParserLiaison owns it
>  XalanNode * _contextNode;//not been deleted at the distructor since
delete
> cause segmentation fault-way?

Because the document owns it, and it's destroyed when the document is
destroyed.

...

> hope some one can help
> regards
> Ifat Tankel

Dave