Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 8:13:00 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

July 2003
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Jun   Aug

Get Firefox!

Wednesday, July 09, 2003

"How can I append the XML generated by writeXML() into another XML document?"

Nodes in a DOM document have the concept of an owning document. DOM 2.0 requires implementations to signal an error when a node from one document is attempted to be added to another document. The only supported technique to "grafting" a chunk of XML from one document to another in DOM 2.0 is to clone the tree of nodes from one document and append it to the target document. However, the Oracle DOM implementation supports a DOM 3.0 feature called "adoptNode" which is much faster since it simply changes the owner document information in the tree of nodes you're trying to append in, rather than forcing you to copy them. The key is the adoptNode() function.on the oracle.xml.parser.v2.XMLDocument class.

This code sample illustrates the technique at work. The result is a new XML document with a document element of <NewRoot> containing the writeXML()-generated XML fragment from BC4J as contained content:

package test;
import oracle.jbo.client.Configuration;
import oracle.jbo.*;
import org.w3c.dom.*;
import oracle.xml.parser.v2.*;
import java.io.*;
public class TestClient  {
  public static void main(String[] args) {
    String _am = "test.TestModule", _cf = "TestModuleLocal";
    ApplicationModule am = Configuration.createRootApplicationModule(_am,_cf);
    ViewObject vo = am.findViewObject("DeptView1");
    Node n = vo.writeXML(1,XMLInterface.XML_OPT_ALL_ROWS);
    XMLDocument newDoc = new XMLDocument();
    Element newDocElt = newDoc.createElement("NewRoot");
    newDoc.appendChild(newDocElt);
    /* Adopt the node from the doc produced by BC4J into your new doc */
    newDoc.adoptNode(n);
    newDocElt.appendChild(n);
    try {
      newDoc.print(System.out);
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
    Configuration.releaseRootApplicationModule(am,true);
  } 
}

9:38:25 PM    



© Copyright 2008 Steve Muench.