Document vs. DocumentFragment

What is the best practice for generating fully-functional XMLDocuments from transforms using XSLProcessor? Most of the processXSL() methods generate DocumentFragments. Why? Sometimes when I append a node from a DocumentFragment to a new XMLDocument (using importNode() or adoptNode()), subsequent xpath operations performed on that XMLDocument won't work or won't produce any nodes.
Also, if I use XMLQuery.setXSLT() and then call getXMLDOM(), I won't get the entire document. Why is this (when if I call getXMLString() and parse the resulting String, my Document will always be complete)?
Also, how can I "Oraclize" an Document using a different DOMImplementation. I can serialize the foreign Document and re-parse it using Oracle's DOMParser, but that seems to defeat the whole concept of using the Document interface in the first place: what's the best practice for using Document objects with different DOMImplementations with Oracle code?
Thanks!

processXSL can either return a DocumentFragment or write the result to a PrintWriter/OutputStream.
It returns DocumentFragment because of section 3.1 in the XSLT 1.0 specification:
"it is possible that a result tree will not be a well-formed XML document;...When the source tree is created in some other way, for example by using the DOM, the usual restrictions are relaxed for the source tree as for the result tree."
This means that you can legally write a transform that produces the result:
<foo/>
<foo/>
<foo/>
which is a list of elements, but not a legal XML document (which would require a single outermost element. DocumentFragment is the only DOM object that allows an arbitrary sequence of DOM nodes that XSLT can produce.
If subsequent xpath operations don't work after successfully appending child nodes to a tree, then that is a bug. Try the latest XDK 9.0.2 Beta which fixes some bugs in that area, and if you still have a problem, report it with a simple testcase here in the forum.
Need to understand more about your XMLQuery.setXSLT() issue and what part of the document is "left out".
You cannot "Oracleize" an org.w3c.dom.Document whose concrete class was created with a different DOMImplementation. We don't support the ability to transform from an arbitrary Document interface for performance reasons. This keeps our XSLT engine very fast. You'll find that engines that accept an arbitrary DOM are never as fast as when they can use their own internal structures.
You can serialize and parse like you've suggested, or tree-walk and fire SAX events as another approach.

Similar Messages

  • How to get document from documentfragment

    hi,
    I tried the xsl Sample Code from Oracle XDK,
    The Output is a documentfragment.
    How can I build a domdocument out of that documentfragment?
    Sorry about the short description, but I think XML Gurus
    know what I mean ;-).
    Thanks
    Deltev

    A DocumentFragment is a 'minimal' Document object.

  • Editing xml documents

    My application uses xml for data persistency. My question is:
    1. is there a way to partially edit part of the xml file? because if I make some small changes to my data, i wish to save just that part.
    2. Or I can just save the whole thing and overwrite the orignal file entirely, is this a common practice?
    thanks!

    A javax.xml.transform.Transformer  transform method stores a Documentnode or a DocumentFragment node.
    Transformer transformer;
    Document document;
    Node node;
    DocumentFragment documentFragment=document.createDocumentFragment();
    documentFragment.appendChild(node);
    transformer.transform(new DOMSource(document), new StreamResult(new File("c:/output/output.xml")));
    transformer.transform(new DOMSource(documentFragment), new StreamResult(new File("c:/output/outputNode.xml")));

  • Encoding problem with XSL

    Hi,
    I have problems when printing the result of processing XML with an XSL that contains locale specific chars.
    Here is a sample:
    XML :
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ListePatients>
    <Patient>
    <Nom>Zeublouse</Nom>
    <NomMarital/>
    <Prinom>Agathe</Prinom>
    </Patient>
    <Patient>
    <Nom>Stick</Nom>
    <NomMarital>Laiboul</NomMarital>
    <Prinom>Ella</Prinom>
    </Patient>
    <Patient>
    <Nom>`ihnotvy</Nom>
    <NomMarital/>
    <Prinom>Jacques</Prinom>
    </Patient>
    </ListePatients>
    XSL :
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="*|/"><xsl:apply-templates/></xsl:template>
    <xsl:template match="text()|@*"><xsl:value-of select="."/></xsl:template>
    <xsl:template match="/">
    <HTML>
    <HEAD>
    <META http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
    <TITLE>Liste de patients</TITLE>
    </HEAD>
    <BODY>
    <xsl:apply-templates select='ListePatients'/>
    </BODY>
    </HTML>
    </xsl:template>
    <xsl:template match='ListePatients'>
    <TABLE>
    <xsl:for-each select='Patient'>
    <xsl:sort select='Nom' order='ascending' data-type='text'/>
    <TR TITLE='`ihnotvy'>
    <TD> <xsl:value-of select='Nom'/> </TD>
    <TD> <xsl:value-of select='NomMarital'/> </TD>
    <TD> <xsl:value-of select='Prinom'/> </TD>
    </TR>
    </xsl:for-each>
    </TABLE>
    </xsl:template>
    </xsl:stylesheet>
    Test program (from Oracle sample) :
    import java.net.URL;
    import java.io.*;
    import oracle.xml.parser.v2.DOMParser;
    import oracle.xml.parser.v2.XMLDocument;
    import oracle.xml.parser.v2.XMLDocumentFragment;
    import oracle.xml.parser.v2.XSLStylesheet;
    import oracle.xml.parser.v2.XSLProcessor;
    public class XSLSampleOTN
    * Transforms an xml document using a stylesheet
    * @param args input xml and xml documents
    public static void main (String args[]) throws Exception
    DOMParser parser;
    XMLDocument xmldoc, xsldoc, out;
    URL xslURL;
    URL xmlURL;
    try
    if (args.length != 2)
    // Must pass in the names of the XSL and XML files
    System.err.println("Usage: java XSLSampleOTN xslfile xmlfile");
    System.exit(1);
    // Parse xsl and xml documents
    parser = new DOMParser();
    parser.setPreserveWhitespace(true);
    // parser input XSL file
    xslURL = DemoUtil.createURL(args[0]);
    parser.parse(xslURL);
    xsldoc = parser.getDocument();
    // parser input XML file
    xmlURL = DemoUtil.createURL(args[1]);
    parser.parse(xmlURL);
    xmldoc = parser.getDocument();
    // instantiate a stylesheet
    XSLStylesheet xslSS = new XSLStylesheet(xsldoc, xslURL);
    XSLProcessor processor = new XSLProcessor();
    // display any warnings that may occur
    processor.showWarnings(true);
    processor.setErrorStream(System.err);
    // Process XSL
    XMLDocumentFragment result = processor.processXSL(xslSS, xmldoc);
    // print the transformed document
    result.print(System.out);
    // an other way to print, it doesn't print the same !!!!
    processor.processXSL(xslSS, xmldoc, System.out);
    catch (Exception e)
    e.printStackTrace();
    When printing the transformed document with DocumentFragment.print() it work fine but when using processXSL(xslSS, xmldoc, System.out) it don't works for locale specific chars and a second <META> balise appears, Why ?
    with DocumentFragment.print(), it's Ok :
    <HTML>
    <HEAD>
    <META http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1"/>
    <TITLE>Liste de patients</TITLE>
    </HEAD>
    <BODY>
    <TABLE>
    <TR TITLE="`ihnotvy">
    <TD>`ihnotvy</TD>
    <TD/>
    <TD>Jacques</TD>
    </TR >
    <TR TITLE="`ihnotvy">
    <TD>Stick</TD>
    <TD>Laiboul</TD>
    <TD>Ella</TD>
    </TR>
    <TR TITLE="`ihnotvy">
    <TD>Zeublouse
    </TD>
    <TD/>
    <TD>Agathe</TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>
    With processXSL(xslSS, xmldoc, System.out), it's not Ok :
    <HTML>
    <HEAD>
    <META http-equiv="Content-Type" content="text/html">
    <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <TITLE>Liste de patients</TITLE>
    </HEAD>
    <BODY>
    <TABLE>
    <TR TITLE="C C)C(C.C/C4C6C9">
    <TD>C C)C(C.C/C4C6C9</TD>
    <TD></TD>
    <TD>Jacques</TD>
    </TR>
    <TR TITLE="C C)C(C.C/C4C6C9">
    <TD>Stick</TD>
    <TD>Laiboul</TD>
    <TD>Ella</TD>
    </TR>
    <TR TITLE="C C)C(C.C/C4C6C9">
    <TD>Zeublouse</TD>
    <TD></TD>
    <TD>Agathe</TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>
    TIA
    Didier
    null

    Two other problems with XSL and print:
    first one :
    XSL :
    <SCRIPT langage="Javascript" type="text/javascript" src="scripts/erreur.js"></SCRIPT>
    DocumentFragment.print() produce :
    <SCRIPT langage="Javascript" type="text/javascript" src="scripts/erreur.js"/>
    => IE5.5 don't load the file !!, it required syntaxe like <SCRIPT ...></SCRIPT> to load.
    the second one :
    XSL:
    <TD><IMG src="images/menuleft.gif"/></TD>
    DocumentFragment.print() produce :
    <TD>
    <IMG src="images/menuleft.gif">
    </TD>
    processXSL(xslSS, xmldoc, System.out) produce :
    <TD><IMG src="images/menuleft.gif">
    </TD>
    Why a cariage return ?? it cause prisentation failure when you want to specifie the size off the cell !!
    TIA
    Didier
    null

  • JDev, XML, and XSLStylesheet

    I'm working through some examples in the O'Reilly, Oracle XML Applications.
    I have the following in MoreoverIntoNewsstory.java
    package mypackage2;
    import oracle.xml.parser.v2.*;
    import java.io.InputStream;
    import org.w3c.dom.*;
    import java.net.URL;
    import java.sql.Connection;
    import oracle.xml.sql.dml.OracleXMLSave;
    public class MoreoverIntoNewsstory {
    public static void main( String[] arg ) throws Exception {
    String theNews = "http://www.moreover.com/cgi-local/page?index_xml+xml",
    theXSL = "c:\\moreover-to-newsstory.xsl";
    // Create a DOM Parser to Parse the News Document
    DOMParser dp = new DOMParser();
    dp.parse( theNews );
    // Parse the document at the URL specified in theURLString
    XMLDocument moreoverNewsDoc = dp.getDocument();
    // Search for a list of all the matching articles and print the count
    NodeList nl = moreoverNewsDoc.selectNodes("moreovernews/article");
    int articleCount = nl.getLength();
    System.out.println("Received " + articleCount + " articles...");
    // Load the XSL Stylesheet from the top-level directory on CLASSPATH
    InputStream xslstream = Object.class.getResourceAsStream(theXSL);
    XSLStylesheet transform = new XSLStylesheet(xslstream,null);
    // Create an instance of XSLProcessor to perform the transformation
    XSLProcessor processor = new XSLProcessor();
    // Transform moreoverNewsDoc by theXSL and get result as a DOM Document Fragment
    DocumentFragment df = processor.processXSL(transform, moreoverNewsDoc);
    // Create a new XML Document and append the fragment to it
    Document result = new XMLDocument();
    result.appendChild(df);
    // Pass the transformed document (now in canonical format) to OracleXMLSave
    Connection conn = Examples.getConnection();
    OracleXMLSave oxs = new OracleXMLSave(conn,"newsstoryview");
    int rowsInserted = oxs.insertXML( result );
    conn.commit();
    conn.close();
    System.out.println("Inserted " + rowsInserted + " articles...");
    When I debug this, it errors at the line:
    XSLStylesheet transform = new XSLStylesheet(xslstream,null);
    The error is:
    Exception breakpoint occurred at line 785 of XSLProcessor.java.
    oracle.xml.parser.v2.XSLException: : XML-22000: (Error) Error while parsing XSL file (null).
    Any advice?

    I thought that might be it to. Tried that, get the same error. I did verify the name and location of the file as well. The error message had the additional notes below:
    Exception breakpoint occurred at line 785 of XSLProcessor.java.
    oracle.xml.parser.v2.XSLException: : XML-22000: (Error) Error while parsing XSL file (null).
    Warning: The debugger has stopped in a class where tracing is disabled.
    Because of the tracing options set in your project, Step Over is not available in this class.
    If you wish to step through this class, please update your tracing options by choosing Tracing... from the context menu in the Classes window.
    Exception in thread main
    java.lang.NullPointerException
         at oracle.xml.parser.v2.XMLReader.pushXMLReader(XMLReader.java:340)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:276)
         at oracle.xml.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:563)
         at oracle.xml.parser.v2.XSLStylesheet.<init>(XSLStylesheet.java:228)
         at mypackage2.MoreoverIntoNewsstory.main(MoreoverIntoNewsstory.java:27)
    Debugger disconnected from local process.
    Process exited.
    The message mentions tracing options. I noticed the message "If you wish to step through this class, please update your tracing options by choosing Tracing... from the context menu in the Classes window."
    Is this something I can do on the oracle proprietary class like XSLProcessor?

  • SQLException "Expected 'EOF'" when extracting XMLType from ResultSet

    Hi,
    I am trying to implement a Java method that returns the nodes matching a given xpath expression. The query is working fine and the code is mostly working. The problem is getting the information out of an XmlType in Java.
    The query is as follows:
    ---8&lt;--
    select extract(res, '/xdb:Resource/xdb:Contents'||:xpath,
    'xmlns:xdb="http://xmlns.oracle.com/xdb/XDBResource.xsd" '||:ns) node
    from resource_view
    where under_path(res, :path) = 1;
    ---8&lt;--
    xpath = '//n:PostalCode'
    ns = 'xmlns:n="uri:cosmos:schema:company:1.0"'
    path = '/home/contactmgr'
    And the Java code:
    ---8&lt;---
    resultSet = statement.executeQuery();
    while (resultSet.next())
    OPAQUE opaque = (OPAQUE) resultSet.getObject(1);
    if (opaque != null)
    XMLType myNode = XMLType.createXML(opaque);
    String testString = myNode.getStringVal();
    Document testDocument = myNode.getDOM();
    ---8&lt;---
    The testString contains the expected result (messy, but workable), i.e. "&lt;PostalCode xmlns="uri:cosmos:schema:company:1.0"&gt;GU1 4LY&lt;/PostalCode&gt;\n&lt;PostalCode xmlns="uri:cosmos:schema:company:1.0"&gt;TW18 4AQ&lt;/PostalCode&gt;\n". These are the two postal codes in the first document.
    The call to myNode.getDOM() fails with an SQLException and a message of "Expected 'EOF'".
    I appreciate that the returned xml is a fragment and as such it shouldn't be possible to return an org.w3c.dom.Document instance. However, when I try using myNode.getDocumentFragment() I still get an SQLException but with no message or any other details.
    The method is currently expected to return a list of Nodes.
    Any ideas?

    The Oracle 10G XDB Developers Guide (http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10790/xdb03usg.htm#sthref209) offers the following:
    "The extract() function returns the node or nodes that match the XPath expression. Nodes are returned as an instance of XMLType. The results of extract() can be either a document or DocumentFragment."
    To provide for the fact that an XPath expression may match multiple nodes in any given document, I modified the query to use xmlsequence(). This should then return an array of XmlType instances.
    --8<--
    select xmlsequence(extract(res, '/xdb:Resource/xdb:Contents'||?,
    'xmlns:xdb="http://xmlns.oracle.com/xdb/XDBResource.xsd"
    '||?)) nodes
    from resource_view
    where under_path(res, ?) = 1;
    --8<--
    The Java JDBC code then looks like this:
    --8<--
    OPAQUE[] myRawNodes = (OPAQUE[]) myResultSet.getArray(1).getArray();
    for (int i = 0; i < myRawNodes.length; i++)
    OPAQUE myOpaque = (OPAQUE) myRawNodes[ i ];
    if (myOpaque != null)
    XMLType myNode = XMLType.createXML(myOpaque);
    myCollection.add(myNode.getDOM());
    --8<--
    Testing this out however, I get the following exception:
    java.sql.SQLException: Internal Error: makeJavaArray doesn't support type 2007
    To re-iterate: my goal is to:
    a) evaluate an XPath expression that will return a list of nodes against all the documents under a particular path in the resource_view;
    b) extract all the returned nodes using JDBC; and
    c) return the collection of nodes to the caller.
    Any ideas?

  • How can I import an XML DOM document into another?

    Dear all,
    I'm using the following bit of code:
         public static Node replaceNode(Document replacedDocument,
                        Document replacingDocument,
                        Node replacedNode)
         //Create a documentFragment of the replacingDocument
         DocumentFragment docFrag = replacingDocument.createDocumentFragment();
         Element rootElement = replacingDocument.getDocumentElement();
         docFrag.appendChild(rootElement);     
         //Import docFrag under the ownership of replacedDocument
         Node replacingNode =
         ((replacedDocument).importNode(docFrag, true));
              //In order to replace the node need to retrieve replacedNode's parent
         Node replaceNodeParent = replacedNode.getParentNode();
         replaceNodeParent.replaceChild(replacingNode, replacedNode);
         return replacedDocument;
    to import a DOM document into another DOM document, so that it converts something like this:
    <?xml= .... etc>
    <Data></Data
    to:
    <?xml= .... etc>
    <Data>
    <Yellow>Butter</Yellow>
    <White>Marzipan</White>
    </Data>
    Instead, what it is doing is:
    <?xml= .... etc>
    <Yellow>Butter</Yellow>
    <White>Marzipan</White>
    I know that it is stripping out the <Data> elements because of the call to the replaceChild
    function, after getting the element's parent, but if I change
    Node replaceNodeParent = replacedNode.getParentNode();
    to
    Node replaceNodeParent = replacedNode;
    I get an error about node node being accessible.
    Please help!
    Paul

    http://forum.java.sun.com/thread.jsp?forum=34&thread=208596

  • Problems with document merge?

    Hi,
    I have installed JDeveloper 9i rc2 and the following code (it runs correctly on JDeveloper 3.2.3)
    Document d = new XMLDocument();
    d.appendChild(d.createElement("d"));
    Document d2 = new XMLDocument();
    d2.appendChild(d2.createElement("d2"));
    DocumentFragment rootNode = new XMLDocumentFragment();
    Element e = d2.getDocumentElement();
    d2.removeChild(e);
    --> rootNode.appendChild(e); /* It is here that the Exception is throwned */
    d.getDocumentElement().appendChild(rootNode.cloneNode(true));
    throws the following exception:
    oracle.xml.parser.v2.XMLDOMException: Node doesn't belong to the current document.
    Any clue why this happen?
    Thanks

    @see org.w3c.dom.Document.importNode

  • How to save a DocumentFragment which is not in XML

    Hi,
    i want to make an export from a view object as CSV-file. To achieve this i have made a stylesheet, that converts a xml to a text format.
    DocumentFragment oDF = tNode.transformNode(xslt);
    And from here i have the problem: How could i save the DocumentFragment to my harddisk? (Inserting that DocumentFragment in a XMLDocument doesn't work because it is no longer in xml-format)
    Thanx,
    Marc

    Hey Marc,
    I'd rather use a code like this:
    DOMParser parser = new DOMParser();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);
    try
    String xslUrl = "yourXSLdocument.xsl";
    parser.parse(is); // the xml document input stream
    XMLDocument doc = parser.getDocument();
    XSLProcessor xp = new XSLProcessor();
    try
    XSLStylesheet xsl = xp.newXSLStylesheet(new FileInputStream(xslUrl));
    xp.processXSL(xsl, doc, pw);
    String processedDoc = baos.toString();
    System.out.println(processedDoc); // Here you go!
    catch (XSLException xsle)
    JOptionPane.showMessageDialog(null, xsle.toString(), "XSLException", JOptionPane.ERROR_MESSAGE);
    catch (SAXException saxe)
    JOptionPane.showMessageDialog(null, saxe.toString(), "SAXException", JOptionPane.ERROR_MESSAGE);
    Please tell me is this is addressing your problem...
    Thank you

  • Problem parsing a html document

    Hi all,
    I need to parse a html document.
    InputStream is = new java.io.FileInputStream(new File("c:/temp/htmldoc.html"));
    DOMFragmentParser DOMparser = new DOMFragmentParser();
    DocumentFragment doc = new HTMLDocumentImpl().createDocumentFragment();
    DOMparser.parse(new InputSource(is), doc);
    NodeList nl = doc.getChildNodes();
    I get just 3 of the following nodes...... though the document htmldoc.html is a proper html doc..
    #document-fragment
    HTML
    #text
    Any suggestions/help are most welcome. Thanks

    Here's an example showing how to do this via javax.xml:
    import java.io.*;
    import java.net.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    public class HTMLElementLister {
         public static void main(String[] args) throws Exception {
              URLConnection con = new URL("http://www.mywebsite.com/index.html").openConnection();
              con.connect();
              InputStream in = (InputStream)con.getContent();
              Document doc = null;
              try {
                   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                   DocumentBuilder db = dbf.newDocumentBuilder();
                   doc = db.parse(in);
              } finally {
                   in.close();
              NodeList nodes = doc.getChildNodes();
              for (int i=0; i<nodes.getLength(); i++) {
                   Node node = nodes.item(i);
                   String nodeName = node.getNodeName();
                   System.out.println(nodeName);
                   if ("html".equalsIgnoreCase(nodeName)) {
                        System.out.println("|");
                        NodeList grandkids = node.getChildNodes();
                        for (int j=0; j<grandkids.getLength(); j++) {
                             Node contentNode = grandkids.item(j);
                             nodeName = contentNode.getNodeName();
                             System.out.println("|- " + nodeName);
                             if ("body".equalsIgnoreCase(nodeName)) {
                                  System.out.println("   |");
                                  NodeList bodyNodes = contentNode.getChildNodes();
                                  for (int k=0; k<bodyNodes.getLength(); k++) {
                                       node = bodyNodes.item(k);
                                       System.out.println("   |- " + node.getNodeName());
    }

  • Appending a DocumentFragment to XMLDocument

    I've been having a surprisingly difficult time trying to do this simple thing: append a DocumentFragment to an XMLDocument.
    Here is my method; there are several print statements in here for debugging:
    * This method joins two XML elements to form a single XML document: the individual
    * SDI element, in an XMLDocument, and the non-SDI parts of the record, in a
    * DocumentFragment. The method assumes that each element has just one child node
    * containing the value. Also assumed is a class object, inputroot, which is a
    * Node that is the root element of an XMLDocument.
    private void joinSDI(XMLDocument sdidoc, DocumentFragment frag)
    NodeList nonSdiNodeList = frag.getChildNodes();
    Node tempRecRoot = sdidoc.getDocumentElement();
    if (DEBUG3)
    System.out.println("length of node list = "+nonSdiNodeList.getLength());
    for (int i = 0; i < nonSdiNodeList.getLength(); i++)
    System.out.println("iteration "+i);
    Node node = nonSdiNodeList.item(i);
    Node n = node.getFirstChild(); // this is the SDI
    System.out.println("source name = " + node.getNodeName());
    System.out.println("source value = " + n.getNodeValue());
    Node tempNode = sdidoc.createTextNode(n.getNodeName());
    tempNode.setNodeValue(n.getNodeValue());
    System.out.println("new node type = " + tempNode.getNodeType());
    System.out.println("new node name = " + tempNode.getNodeName());
    System.out.println("new node value = " + tempNode.getNodeValue());
    tempRecRoot.appendChild(tempNode);
    // Now append this record XML doc to the insertion document we are building.
    System.out.println("the constructed input doc:");
    try {
    sdidoc.print(System.out);
    catch (IOException e)
    System.out.println("Caught IO parse exception : "+e.getMessage());
    this.inputroot.appendChild(sdidoc);
    return;
    Here is the input xml doc:
    <?xml version="1.0" encoding="US-ASCII" standalone="no"?>
    <!DOCTYPE hydro SYSTEM "hydro.dtd">
    <hydro>
    <ROW num="1">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
    <VALUE>644.039978</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    <ROW num="2">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 13:00:00</DATE_HOUR>
    <VALUE>111</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    <ROW num="3">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 14:00:00</DATE_HOUR>
    <VALUE>333</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    </hydro>
    Here is what I get for output (including the debugging statements):
    null

    I've been having a surprisingly difficult time trying to do this simple thing: append a DocumentFragment to an XMLDocument.
    Here is my method; there are several print statements in here for debugging:
    * This method joins two XML elements to form a single XML document: the individual
    * SDI element, in an XMLDocument, and the non-SDI parts of the record, in a
    * DocumentFragment. The method assumes that each element has just one child node
    * containing the value. Also assumed is a class object, inputroot, which is a
    * Node that is the root element of an XMLDocument.
    private void joinSDI(XMLDocument sdidoc, DocumentFragment frag)
    NodeList nonSdiNodeList = frag.getChildNodes();
    Node tempRecRoot = sdidoc.getDocumentElement();
    if (DEBUG3)
    System.out.println("length of node list = "+nonSdiNodeList.getLength());
    for (int i = 0; i < nonSdiNodeList.getLength(); i++)
    System.out.println("iteration "+i);
    Node node = nonSdiNodeList.item(i);
    Node n = node.getFirstChild(); // this is the SDI
    System.out.println("source name = " + node.getNodeName());
    System.out.println("source value = " + n.getNodeValue());
    Node tempNode = sdidoc.createTextNode(n.getNodeName());
    tempNode.setNodeValue(n.getNodeValue());
    System.out.println("new node type = " + tempNode.getNodeType());
    System.out.println("new node name = " + tempNode.getNodeName());
    System.out.println("new node value = " + tempNode.getNodeValue());
    tempRecRoot.appendChild(tempNode);
    // Now append this record XML doc to the insertion document we are building.
    System.out.println("the constructed input doc:");
    try {
    sdidoc.print(System.out);
    catch (IOException e)
    System.out.println("Caught IO parse exception : "+e.getMessage());
    this.inputroot.appendChild(sdidoc);
    return;
    Here is the input xml doc:
    <?xml version="1.0" encoding="US-ASCII" standalone="no"?>
    <!DOCTYPE hydro SYSTEM "hydro.dtd">
    <hydro>
    <ROW num="1">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
    <VALUE>644.039978</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    <ROW num="2">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 13:00:00</DATE_HOUR>
    <VALUE>111</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    <ROW num="3">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 14:00:00</DATE_HOUR>
    <VALUE>333</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    </hydro>
    Here is what I get for output (including the debugging statements):
    null

  • XMLType.getDOM().createDocumentFragment() NOT org.w3c.dom.DocumentFragment ?

    Hi,
    i have an XMLType variable xml ( (XMLType) ResultSet.getObject() ) and i want to create an org.w3c.DocumentFragment by : xml.createDocumentFragment(). But i get a ClassCastException.
    oracle.xdb.dom.XDBDocumentFragment does not implement org.w3c.dom.DocumentFragment ?
    Thanks
    Alessandro Scotti

    I think that oracle.xdb.dom.XDBDocumentFragment is "internal" oracle view of org.w3c.dom.DocumentFragment
    because xmltype!= DOM Document.One question:
    how I can implement org.w3c.dom.DocumentFragment.getOwnerDocument() method?
    Regards.

  • Appendchild from DocumentFragment

    Hello:
    I need help in understanding the issue with the code specifically documentfragment. On searching the forums, I could find an alternate way of getting the required result. However I am interested in understanding why my original code with DocumentFragment does not work. I am not able to understand why the Node created from DocumentFragment wont get added as Child in the main XML after I have imported it.
    I am running this on 10g - version 10.2.0.4 database.
    Orginal Code
    DECLARE
    l_xml DBMS_XMLDOM.DOMDocument;
    l_tmp_xml DBMS_XMLDOM.DOMDocument;
    l_root_node DBMS_XMLDOM.DOMNode;
    l_curr_node DBMS_XMLDOM.DOMNode;
    l_node DBMS_XMLDOM.DOMNode;
    l_element DBMS_XMLDOM.DOMElement;
    l_fragment DBMS_XMLDOM.DOMDocumentFragment;
    l_cnt_req NUMBER := 0;
    l_cnt_obj NUMBER := 0;
    l_c CLOB;
    l_buffer varchar2(4000);
    elem DBMS_XMLDOM.DOMELEMENT;
    BEGIN
    l_xml := DBMS_XMLDOM.newDOMDocument();
    DBMS_XMLDOM.setVersion(l_xml, '1.0');
    DBMS_XMLDOM.setCharset(l_xml, 'windows-1251');
    DBMS_XMLDOM.setStandalone(l_xml, 'yes');
    l_element := DBMS_XMLDOM.createElement(l_xml, 'rde');
    l_root_node := DBMS_XMLDOM.makeNode(l_element);
    l_node := DBMS_XMLDOM.makeNode(l_xml);
    l_node := DBMS_XMLDOM.appendChild(l_node, l_root_node);
    l_element := DBMS_XMLDOM.createElement(l_xml, 'data');
    l_node := DBMS_XMLDOM.makeNode(l_element);
    l_root_node := DBMS_XMLDOM.appendChild(l_root_node, l_node);
    FOR cur_req IN (
    SELECT XMLELEMENT("PARTYADDRESSES",
    XMLELEMENT("VOBASECOLLECTION",
    XMLELEMENT("VOPartyAddress",
    XMLFOREST(POVS.VENDOR_SITE_ID AS "PartyAddressId",
    'Street' AS "AddressType",
    POVS.CREATION_DATE AS "EffectDtFrom",
    POVS.INACTIVE_DATE AS "EffectDtTo",
    DECODE(POVS.INACTIVE_DATE,NULL,'TRUE','FALSE') AS "IsCurrent",
    0 AS "UploadPackageId",
    0 AS "UploadBatchId",
    0 AS "AddressId",
    POVS.ADDRESS_LINE1 ||' '||
    POVS.ADDRESS_LINE2 ||' '||
    POVS.ADDRESS_LINE3 AS "Street"),
    XMLELEMENT("CityID", XMLATTRIBUTES('city' AS "location_type",
    POVS.CITY AS "name",
    POVS.STATE AS "owner_id")),
    XMLELEMENT("ZipCode",POVS.ZIP),
    XMLELEMENT("CountryRegionID",XMLATTRIBUTES('Country' AS "location_type",
    'United States' AS "name",
    'The World' As "Owner_id"))))).GetClobVal() AS PartyAddressesXML
    FROM PO_VENDORS POV,
    PO_VENDOR_SITES_ALL POVS
    WHERE POV.VENDOR_ID = POVS.VENDOR_ID
    AND POVS.VENDOR_SITE_ID = 2385298)
    LOOP
    l_tmp_xml := DBMS_XMLDOM.newDOMDocument(cur_req.PartyAddressesXML);
    l_fragment := DBMS_XMLDOM.createDocumentFragment(l_tmp_xml);
    l_curr_node := DBMS_XMLDOM.makeNode(l_fragment);
    DBMS_XMLDOM.WRITETOBUFFER(l_tmp_xml,l_buffer);
    dbms_output.put_line(l_buffer);
    l_curr_node := DBMS_XMLDOM.IMPORTNODE(l_xml,l_curr_node,TRUE);
    l_curr_node := DBMS_XMLDOM.APPENDCHILD(l_node, l_curr_node);
    DBMS_XMLDOM.freeDocument(l_tmp_xml);
    END LOOP; --FOR cur_req
    DBMS_XMLDOM.WRITETOBUFFER(l_xml,l_buffer);
    dbms_output.put_line(l_buffer);
    END;
    Output
    <PARTYADDRESSES><VOBASECOLLECTION><VOPartyAddress><PartyAddressId>2385298</PartyAddressId><AddressType>Street</AddressType><EffectDtFrom>2009-11-21</EffectDtFrom><IsCurrent>TRUE</IsCurrent><UploadPackageId>0</UploadPackageId><UploadBatchId>0</UploadBatchId><AddressId>0</AddressId><Street>PO BOX 6685 </Street><CityID location_type="city" name="GREENVILLE" owner_id="SC"></CityID><ZipCode>29606</ZipCode><CountryRegionID location_type="Country" name="United States" Owner_id="The World"></CountryRegionID></VOPartyAddress></VOBASECOLLECTION></PARTYADDRESSES>
    <?xml version="1.0" standalone='yes'?>
    <rde>
    <data/>
    </rde>
    Code that gives Required Output
    DECLARE
    l_xml DBMS_XMLDOM.DOMDocument;
    l_tmp_xml DBMS_XMLDOM.DOMDocument;
    l_root_node DBMS_XMLDOM.DOMNode;
    l_curr_node DBMS_XMLDOM.DOMNode;
    l_node DBMS_XMLDOM.DOMNode;
    l_worknode DBMS_XMLDOM.DOMNode;
    l_add_node DBMS_XMLDOM.DOMNode;
    l_element DBMS_XMLDOM.DOMElement;
    l_fragment DBMS_XMLDOM.DOMDocumentFragment;
    l_cnt_req NUMBER := 0;
    l_cnt_obj NUMBER := 0;
    l_c CLOB;
    l_buffer varchar2(4000);
    elem DBMS_XMLDOM.DOMELEMENT;
    BEGIN
    l_xml := DBMS_XMLDOM.newDOMDocument();
    DBMS_XMLDOM.setVersion(l_xml, '1.0');
    DBMS_XMLDOM.setCharset(l_xml, 'windows-1251');
    DBMS_XMLDOM.setStandalone(l_xml, 'yes');
    l_element := DBMS_XMLDOM.createElement(l_xml, 'rde');
    l_root_node := DBMS_XMLDOM.makeNode(l_element);
    l_node := DBMS_XMLDOM.makeNode(l_xml);
    l_node := DBMS_XMLDOM.appendChild(l_node, l_root_node);
    l_element := DBMS_XMLDOM.createElement(l_xml, 'data');
    l_node := DBMS_XMLDOM.makeNode(l_element);
    l_root_node := DBMS_XMLDOM.appendChild(l_root_node, l_node);
    FOR cur_req IN (
    SELECT XMLELEMENT("PARTYADDRESSES",
    XMLELEMENT("VOBASECOLLECTION",
    XMLELEMENT("VOPartyAddress",
    XMLFOREST(POVS.VENDOR_SITE_ID AS "PartyAddressId",
    'Street' AS "AddressType",
    POVS.CREATION_DATE AS "EffectDtFrom",
    POVS.INACTIVE_DATE AS "EffectDtTo",
    DECODE(POVS.INACTIVE_DATE,NULL,'TRUE','FALSE') AS "IsCurrent",
    0 AS "UploadPackageId",
    0 AS "UploadBatchId",
    0 AS "AddressId",
    POVS.ADDRESS_LINE1 ||' '||
    POVS.ADDRESS_LINE2 ||' '||
    POVS.ADDRESS_LINE3 AS "Street"),
    XMLELEMENT("CityID", XMLATTRIBUTES('city' AS "location_type",
    POVS.CITY AS "name",
    POVS.STATE AS "owner_id")),
    XMLELEMENT("ZipCode",POVS.ZIP),
    XMLELEMENT("CountryRegionID",XMLATTRIBUTES('Country' AS "location_type",
    'United States' AS "name",
    'The World' As "Owner_id"))))).GetClobVal() AS PartyAddressesXML
    FROM PO_VENDORS POV,
    PO_VENDOR_SITES_ALL POVS
    WHERE POV.VENDOR_ID = POVS.VENDOR_ID
    AND POVS.VENDOR_SITE_ID = 2385298)
    LOOP
    l_tmp_xml := DBMS_XMLDOM.newDOMDocument(cur_req.PartyAddressesXML);
    l_curr_node := dbms_xmldom.makeNode(dbms_xmldom.getDocumentElement(l_tmp_xml));
    l_curr_node := DBMS_XMLDOM.IMPORTNODE(l_xml,l_curr_node,true);
    l_curr_node := DBMS_XMLDOM.APPENDCHILD(l_node, l_curr_node);
    DBMS_XMLDOM.freeDocument(l_tmp_xml);
    END LOOP; --FOR cur_req
    DBMS_XMLDOM.WRITETOBUFFER(l_xml,l_buffer);
    dbms_output.put_line(l_buffer);
    DBMS_XMLDOM.freeDocument(l_xml);
    Exception
    When others then
    dbms_output.put_line (sqlerrm);
    END;
    Desired Output
    <?xml version="1.0" standalone='yes'?>
    <rde>
    <data>
    <PARTYADDRESSES>
    <VOBASECOLLECTION>
    <VOPartyAddress>
    <PartyAddressId>2385298</PartyAddressId>
    <AddressType>Street</AddressType>
    <EffectDtFrom>2009-11-21</EffectDtFrom>
    <IsCurrent>TRUE</IsCurrent>
    <UploadPackageId>0</UploadPackageId>
    <UploadBatchId>0</UploadBatchId>
    <AddressId>0</AddressId>
    <Street>PO BOX 6685 </Street>
    <CityID location_type="city" name="GREENVILLE" owner_id="SC"/>
    <ZipCode>29606</ZipCode>
    <CountryRegionID location_type="Country" name="United States" Owner_id="The World"/>
    </VOPartyAddress>
    </VOBASECOLLECTION>
    </PARTYADDRESSES>
    </data>
    </rde>

    A DocumentFragment is a 'minimal' Document object.

  • Appending a DocumentFragment to XMLDocument (acutal)

    (Sorry for previous incorrect post, which was incomplete; this is the correct post.)
    I've been having a surprisingly difficult time trying to do this simple thing: append a DocumentFragment to an XMLDocument.
    Here is my method; there are several print statements in here for debugging:
    * This method joins two XML elements to form a single XML document: the individual
    * SDI element, in an XMLDocument, and the non-SDI parts of the record, in a
    * DocumentFragment. The method assumes that each element has just one child node
    * containing the value. Also assumed is a class object, inputroot, which is a
    * Node that is the root element of an XMLDocument.
    private void joinSDI(XMLDocument sdidoc, DocumentFragment frag)
    NodeList nonSdiNodeList = frag.getChildNodes();
    Node tempRecRoot = sdidoc.getDocumentElement();
    if (DEBUG3)
    System.out.println("length of node list = "+nonSdiNodeList.getLength());
    for (int i = 0; i < nonSdiNodeList.getLength(); i++)
    System.out.println("iteration "+i);
    Node node = nonSdiNodeList.item(i);
    Node n = node.getFirstChild(); // this is the SDI
    System.out.println("source name = " + node.getNodeName());
    System.out.println("source value = " + n.getNodeValue());
    Node tempNode = sdidoc.createTextNode(n.getNodeName());
    tempNode.setNodeValue(n.getNodeValue());
    System.out.println("new node type = " + tempNode.getNodeType());
    System.out.println("new node name = " + tempNode.getNodeName());
    System.out.println("new node value = " + tempNode.getNodeValue());
    tempRecRoot.appendChild(tempNode);
    // Now append this record XML doc to the insertion document we are building.
    System.out.println("the constructed input doc:");
    try {
    sdidoc.print(System.out);
    catch (IOException e)
    System.out.println("Caught IO parse exception : "+e.getMessage());
    this.inputroot.appendChild(sdidoc);
    return;
    Here is the input xml doc:
    <?xml version="1.0" encoding="US-ASCII" standalone="no"?>
    <!DOCTYPE hydro SYSTEM "hydro.dtd">
    <hydro>
    <ROW num="1">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
    <VALUE>644.039978</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    <ROW num="2">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 13:00:00</DATE_HOUR>
    <VALUE>111</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    <ROW num="3">
    <HM_SITE_CODE>HDMLC</HM_SITE_CODE>
    <HM_PCODE>TRACE</HM_PCODE>
    <DATE_HOUR>14-APR-00 14:00:00</DATE_HOUR>
    <VALUE>333</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROW>
    </hydro>
    Here is what I get for output (including the debugging statements):
    length of node list = 4
    iteration 0
    source name = DATE_HOUR
    source value = 14-APR-00 12:00:00
    new node type = 3
    new node name = #text
    new node value = 14-APR-00 12:00:00
    iteration 1
    source name = VALUE
    source value = 644.039978
    new node type = 3
    new node name = #text
    new node value = 644.039978
    iteration 2
    source name = SOURCE_ID
    source value = 4
    new node type = 3
    new node name = #text
    new node value = 4
    iteration 3
    source name = VALIDATION
    source value = Z
    new node type = 3
    new node name = #text
    new node value = Z
    the constructed input doc:
    <?xml version = '1.0'?>
    <ROWSET><ROW num="1"><SITE_DATATYPE_ID>2158</SITE_DATATYPE_ID></ROW>14-APR-00 12:00:00644.0399784Z</ROWSET>
    Exception in thread "main" java.lang.NullPointerException
    at Hdbdom.joinSDI(Compiled Code)
    at Hdbdom.addRec(Hdbdom.java:534)
    at Hdbdom.buildInsertQry(Compiled Code)
    at Hdbdom.parsedoc(Hdbdom.java:228)
    at Hdbdom.main(Hdbdom.java:695)
    I am puzzled by several things here:
    - why i s the node name #text in the new document?
    - why are my node values all jammed together in the output instead of becoming separate nodes?
    - how do I set the doctype in the output document?
    - why do I get a null pointer when attempting to append this output doc to the inputroot object?
    Any help would be much appreciated,
    --Rick Casey
    null

    package package2;
    import oracle.xml.parser.v2.*;
    import org.w3c.dom.*;
    import java.io.*;
    public class Class1
    public static void main(String [] a) throws Throwable {
    DOMParser d = new DOMParser();
    d.parse(new StringReader("<x><y/><z/></x>"));
    XMLDocument doc = d.getDocument();
    DocumentFragment frag = doc.createDocumentFragment();
    frag.appendChild(doc.createElement("extra-foo"));
    appendFrag(doc,frag);
    doc.print(System.out);
    public static void appendFrag(XMLDocument doc, DocumentFragment frag) {
    doc.getDocumentElement().appendChild(frag);
    }<HR></BLOCKQUOTE>
    Excellent! Thank you!
    That worked, except that the fragment gets appended after the trailing </ROW> tag.
    Here's an example of the incorrect append:
    <?xml version = '1.0'?>
    <ROWSET>
    <ROW num="1"> <SITE_DATATYPE_ID>2158</SITE_DATATYPE_ID>
    </ROW>
    <DATE_HOUR>14-APR-00 12:00:00</DATE_HOUR>
    <VALUE>644.039978</VALUE>
    <SOURCE_ID>4</SOURCE_ID>
    <VALIDATION>Z</VALIDATION>
    </ROWSET>
    Is there an easy way to append such that my elements appear after the <SITE_DATATYPE_ID> element within the <ROW> tag?
    TIA!
    --Rick Caesy
    <HR></BLOCKQUOTE>
    Steve,
    Nevermind my previous question; I answered it myself -- for those interested, the (very easy) solution was:
    sdidoc.getDocumentElement().getFirstChild().appendChild(frag);
    --Rick Casey                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Error while resetting a cleared document

    Hi everyone,
    I am getting an error while resetting a cleared invoicing document 'Document xxxxxxxxxxx with origin R4 can not be reversed'. Please guide me how can we reset the clearing of this document.
    Thanks and Regards

    Hi,
    You need to reset all clearing for the corresponding FICA document for the print document.
    Reset the clearing for the document no. mentioned in the output for EA13 execution.
    You need to reset all the clearing for the document, before reversing the same.
    To get all the clearing document, go to DFKKOP table, enter the FICA document no. (for the print document on FPL9). Get all AUGBL documents,
    Alternatively, you can go on to FPL9 screen, double click on the consumption document, in the basic data you will see the clearing date (if it is cleared), expand the view their (click on + sign), you will se the clearing document no,
    Pass the above clearing document no, to FP07, and once all the clearing is reset for the invoice, you can reverse the corresponding invoice through EA13.
    Regards,
    Rajesh Popat

Maybe you are looking for

  • How to get rid of adobe Pop up

    Hi, Hope some one can help. How can I get rid of a adobe popup in the middle of my screen? When running the tutorials theres a adobe 'project created by' pop up in the middle of the screen. It's actually there right from the beginning. I've also crea

  • Iweb 08 hangs or very slow to start at times.

    Hi all Iweb 2.0.2 on mac osx 10.5.1 (leopard) at times very - very slow to start or quit - shown in activity monitor and "force quit" as "not responding". It does however eventually start and quit. This problem appeared out of the blue and occurred a

  • Is it bad to use Fan Control?

    So I was looking into running Boinc (donating CPU time to run science projects aka grid computing) on my computer and installed Fan Control so I turn up my fans to keep to comp cooler. I have hence been convinced that it isn't the best idea to run yo

  • Analytics 1.1

    I am installating Analytics 1.1 on Plumtree 5.03/colab 4.02. Installation went fine and tracking all community/portal traffic. How ever sync job is not retreiving projects and document information. Getting errors like 23 Mar 2006 10:40:06,325 WARN JD

  • The importance of Permissions

    This is just an FYI post. The other night I installed a Major Graphics Suite on my Imac. Everything seemed to work fine until yesterday. When I tried to log into my POP e-mail acount I was getting a password not recognized return from the server. I w