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 ol...@invensys.com on 2003/01/27 23:50:58 UTC

xalan and importNode

G'day all,

I am attempting to use the XalanDocumentBuilder to create an input source
for the transformer, pretty much as per the DocumentBuilder sample. But
after creating part of the input document programmatically, I then want to
open another XML document and append its content to the document I have
just built. In other words something like:

            XalanDocumentBuilder* pDocBuilder =
xalanTransformer.createDocumentBuilder();

     /* lotsa SAX calls... */

            XalanDocument* pDocToConcatenate = liasion.parseXMLStream(/*
xml file */);
            XalanNode* pTheirNode = pDocToConcatenate->getDocumentElement
();

            XalanNode* pOurNode = pDocBuilder->getDocument()
->importNode(pTheirNode, true);
            pDocBuilder->getDocument()->/* get the appropriate element */
->appendChild(pOurNode);

What happens is that the importNode call throws a XalanDOMException,
NO_MODIFICATION_ALLOWED_ERR .

Can anyone explain why and what an alternative approach to merging XML
fragments from multiple documents might be?

TIA.

==============================
Oliver White
Software Engineer
Product Development
Westinghouse Signals Australia
==============================



Re: xalan and importNode

Posted by David N Bertoni/Cambridge/IBM <da...@us.ibm.com>.



Hi Oliver,

You have the build the source tree in document order, so you should build
until you get to the point where you want to append something else, then
append it.  You can then continue to build the document dynamically.

Typically, you would build a SAX filter based on ContentHandler,
LexicalHandler, etc. that would ignore the parsing events you don't want,
but pass the others on to the XalanDocumentBuilder instance.  In this case,
since you're just appending the document element of the parsed document,
that would be:

   1. startDocument() and endDocument()
   2. Any events before the first startElement()
   3. Any events after the corresponding endElement()

Note this is drastically more efficient than parsing the entire document
and importing its document element, because you build the nodes into the
main tree as the parser is sending the SAX events.  Your method, if it were
supported, would build a separate tree and copy the imported nodes into the
main tree.

Hope that helps...

Dave



                                                                                                                                        
                      oliver.white@inv                                                                                                  
                      ensys.com                To:      xalan-c-users@xml.apache.org                                                    
                                               cc:      (bcc: David N Bertoni/Cambridge/IBM)                                            
                      01/27/2003 02:50         Subject: xalan and importNode                                                            
                      PM                                                                                                                
                                                                                                                                        




G'day all,

I am attempting to use the XalanDocumentBuilder to create an input source
for the transformer, pretty much as per the DocumentBuilder sample. But
after creating part of the input document programmatically, I then want to
open another XML document and append its content to the document I have
just built. In other words something like:

            XalanDocumentBuilder* pDocBuilder =
xalanTransformer.createDocumentBuilder();

     /* lotsa SAX calls... */

            XalanDocument* pDocToConcatenate = liasion.parseXMLStream(/*
xml file */);
            XalanNode* pTheirNode = pDocToConcatenate->getDocumentElement
();

            XalanNode* pOurNode = pDocBuilder->getDocument()
->importNode(pTheirNode, true);
            pDocBuilder->getDocument()->/* get the appropriate element */
->appendChild(pOurNode);

What happens is that the importNode call throws a XalanDOMException,
NO_MODIFICATION_ALLOWED_ERR .

Can anyone explain why and what an alternative approach to merging XML
fragments from multiple documents might be?

TIA.

==============================
Oliver White
Software Engineer
Product Development
Westinghouse Signals Australia
==============================