Can't create a temporary document from an XmlInputStream

Attempts to create an XmlDocument fail when reading it from an XmlInputStream
MainXmlInput.java
package com.kitfox.dbtest;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlInputStream;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlManagerConfig;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlResolver;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlTransaction;
import com.sleepycat.dbxml.XmlValue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
class DatabaseResolver extends XmlResolver {
    public boolean resolveDocument(XmlTransaction txn, XmlManager mgr,
            String uri, XmlValue val)
            throws XmlException {
        System.err.println("<--->");
        throw new UnsupportedOperationException("Not supported yet.");
    public boolean resolveCollection(XmlTransaction txn, XmlManager mgr,
            String uri, XmlResults res)
            throws XmlException {
        System.err.println("<--->");
        throw new UnsupportedOperationException("Not supported yet.");
    public XmlInputStream resolveSchema(XmlTransaction txn, XmlManager mgr,
            String location, String nameSpace)
            throws XmlException {
        InputStream in = DatabaseResolver.class.getResourceAsStream(location);
        return in == null ? null : mgr.createInputStream(in);
    public XmlInputStream resolveEntity(XmlTransaction txn, XmlManager mgr,
            String systemId, String publicId)
            throws XmlException {
        System.err.println("<--->");
        throw new UnsupportedOperationException("Not supported yet.");
    public boolean resolveModuleLocation(XmlTransaction txn, XmlManager mgr,
            String nameSpace, XmlResults result)
            throws XmlException {
        System.err.println("<--->");
        throw new UnsupportedOperationException("Not supported yet.");
    @Override
    public XmlInputStream resolveModule(XmlTransaction txn, XmlManager mgr,
            String moduleLocation, String nameSpace)
            throws XmlException
//        System.err.println("<--->");
//        throw new UnsupportedOperationException("Not supported yet.");
        InputStream in = DatabaseResolver.class.getResourceAsStream(moduleLocation);
        return in == null ? null : mgr.createInputStream(in);
class Database
    public static final String DATABASE_NS = "http://xml.kitfox.com/schema/database";
    public static final String CONTAINER_NAME = "base.dbxml";
    public static final String DOCUMENT_NAME = "test.xml";
    public static final String DOCUMENT_URI = "dbxml:/"
            + CONTAINER_NAME
            + "/"
            + DOCUMENT_NAME;
    public static final String DOCUMENT_PREFIX = "doc(\"dbxml:/"
            + CONTAINER_NAME
            + "/"
            + DOCUMENT_NAME + "\")";
    final File home;
    Environment env;
    XmlManager manager;
    XmlContainer container;
    Database(File home, boolean createIfAbsent)
        this.home = home;
        try {
            EnvironmentConfig config = new EnvironmentConfig();
            config.setAllowCreate(createIfAbsent);
            config.setInitializeLocking(true);
            config.setInitializeLogging(true);
            config.setInitializeCache(true);
            config.setTransactional(true);
            config.setRunRecovery(true);
            config.setThreaded(true);
            //config.setLockDetectMode(LockDetectMode.DEFAULT);
            env = new Environment(home, config);
            XmlManagerConfig managerConfig = new XmlManagerConfig();
            managerConfig.setAllowAutoOpen(true);
            managerConfig.setAdoptEnvironment(true);
            managerConfig.setAllowExternalAccess(true);
            manager = new XmlManager(env, managerConfig);
            manager.setDefaultContainerType(XmlContainer.NodeContainer);
            manager.registerResolver(new DatabaseResolver());
            if (manager.existsContainer(CONTAINER_NAME) == 0) {
                container = manager.createContainer(CONTAINER_NAME);
                //Initial document
                    InputStream is = null;
                    XmlInputStream xin = null;
                    URL initXml = getClass().getResource("/com/kitfox/dbtest/init.xml");
                    is = initXml.openStream();
                    xin = manager.createInputStream(is);
                    container.putDocument(DOCUMENT_NAME, xin);
                    xin.delete();
            } else {
                container = manager.openContainer(CONTAINER_NAME);
        } catch (IOException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DatabaseException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    public void dispose()
        try {
            if (container != null)
                container.close();
                container = null;
            if (manager != null)
                manager.close();
                manager = null;
                //manager will auto close env
                env = null;
        } catch (DatabaseException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    public void dump(PrintStream ps)
        try {
            XmlQueryContext ctx = manager.createQueryContext();
            String query = DOCUMENT_PREFIX;
            XmlResults res = manager.query(query, ctx);
            XmlValue value = res.next();
            value.getTypeName();
            value.getTypeURI();
            ps.println(value.asString());
            res.delete();
            ctx.delete();
        } catch (XmlException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    public String runQuery(URL queryURL)
        XmlQueryContext ctx = null;
        XmlResults res = null;
        XmlDocument queryDoc = null;
        String resp = null;
        try {
            XmlInputStream xin = manager.createInputStream(queryURL.openStream());
            queryDoc = manager.createDocument();
            queryDoc.setContentAsXmlInputStream(xin);
            XmlValue docValue = new XmlValue(queryDoc);
            if ("".equals(docValue.asString()))
                throw new RuntimeException("Empty document!");
            ctx = manager.createQueryContext();
            ctx.setVariableValue("docURI", new XmlValue(DOCUMENT_URI));
            ctx.setVariableValue("request", docValue);
            docValue.asString();
            String query =
                    "import module namespace gbfn = 'http://xml.kitfox.com/xquery/test' at '/com/kitfox/dbtest/functions.xq';"
                    + "\n gbfn:runQuery(doc($docURI), $request)"
            res = manager.query(query, ctx);
            XmlValue respValue = res.next();
            resp = respValue.asString();
        } catch (IOException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        } catch (XmlException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        finally {
            if (queryDoc != null)
                queryDoc.delete();
            if (res != null)
                res.delete();
            if (ctx != null)
                ctx.delete();
        return resp;
* @author kitfox
public class MainXmlInput {
    public static void deleteRecursive(File curFile)
        if (curFile.isDirectory())
            for (File file: curFile.listFiles())
                deleteRecursive(file);
        curFile.delete();
     * @param args the command line arguments
    public static void main(String[] args) {
        File root = new File("gamedb");
        //Cleanup test dir
        deleteRecursive(root);
        root.mkdir();
        //Create the database
        Database gb = new Database(root, true);
        //Setting this to true will let all of the below tests run, but will
        // not solve some more complex queries that are not included in this
        // example
        if (false)
            gb.dispose();
            gb = new Database(root, true);
        System.err.println(gb.runQuery(MainXmlInput.class.getResource("/com/kitfox/dbtest/query.xml")));
        gb.dispose();
}functions.xq
module namespace gbq = "http://xml.kitfox.com/xquery/test";
declare namespace err = "http://xml.kitfox.com/xquery/gamebase/error";
declare function gbq:dump($root as node()) as element()
    $root/element()
declare function gbq:runQuery($doc as document-node(), $req as document-node()) as element()
    $req/element()
declare updating function gbq:runUpdate($doc as document-node(), $req as document-node())
    let $element := $req/root/element()
        return insert node <entry>{$element}</entry> into $doc/squirrel
};init.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <squirrel>
        <peanut/>
    </squirrel>
</root>query.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <larry>
        <curly>
            <moe/>
        </curly>
    </larry>
</root>

Here is a patch for your problem. Please tell me if it works.
Lauren Foutz
diff -r 3ea6fcd222af src/dbxml/Document.cpp
--- a/src/dbxml/Document.cpp     Wed Nov 05 12:39:38 2008 -0500
+++ b/src/dbxml/Document.cpp     Tue Nov 18 10:11:16 2008 -0500
@@ -571,6 +571,10 @@
          consumed(getName(), consumed_);
          ret = new MemBufInputStream(0, 0, getName().c_str(),false);
+     if(definitiveContent_ == DBT) {
+          dbtContent_ = 0;
+          definitiveContent_ = NONE;
+     }
     return ret;
@@ -680,6 +684,7 @@
     changeContentToNsDom(isns);
+     if (!nsDocument_) return 0; //empty document
     if (nid.isDocRootNid())
          return nsDocument_->getDocumentNode();
     NsNode *nsNode = nsDocument_->getNode(nid, /*getNext*/false);
diff -r 3ea6fcd222af src/dbxml/DocumentDatabase.cpp
--- a/src/dbxml/DocumentDatabase.cpp     Wed Nov 05 12:39:38 2008 -0500
+++ b/src/dbxml/DocumentDatabase.cpp     Tue Nov 18 10:11:16 2008 -0500
@@ -184,9 +184,6 @@
               id = ((Document&)old_document).getID();
               new_document.getIDToSet() = id;
               resetId = true;
-               // clear modified flag if set on name
-               const_cast<Document*>(&new_document)->
-                    clearModified(Name(metaDataName_uri_name));
     } else {
          err = indexer.getContainer()->getDocument(
diff -r 3ea6fcd222af src/dbxml/nodeStore/NsDocumentDatabase.cpp
--- a/src/dbxml/nodeStore/NsDocumentDatabase.cpp     Wed Nov 05 12:39:38 2008 -0500
+++ b/src/dbxml/nodeStore/NsDocumentDatabase.cpp     Tue Nov 18 10:11:16 2008 -0500
@@ -173,9 +173,6 @@
               id = ((Document&)old_document).getID();
               new_document.getIDToSet() = id;
               resetId = true;
-               // clear modified flag if set on name
-               const_cast<Document*>(&new_document)->
-                    clearModified(Name(metaDataName_uri_name));
     } else {
diff -r 3ea6fcd222af src/java/com/sleepycat/dbxml/XmlDocument.java
--- a/src/java/com/sleepycat/dbxml/XmlDocument.java     Wed Nov 05 12:39:38 2008 -0500
+++ b/src/java/com/sleepycat/dbxml/XmlDocument.java     Tue Nov 18 10:11:16 2008 -0500
@@ -115,9 +115,7 @@
         content.stream = null;
         content.type = NONE;
         return ins;
-     }else if (!content.hasContent() && docID == 0)
-         return null;
-     else
+     } else
         return HelperFunctions.getContentAsXmlInputStream(this);
@@ -127,9 +125,7 @@
         content.reader = null;
         content.type = NONE;
         return xer;
-     }else if (!content.hasContent() && docID == 0)
-         return null;
-     else
+     } else
         return HelperFunctions.getContentAsEventReader(this);
@@ -214,6 +210,13 @@
     //The rest of this class is for internal use.
+    protected boolean isConstructed()
+    {
+         if(results == null && docID == 0)
+              return true;
+         return false;
+    }
+   
     /* If both modified and removed are set to false then the meta data is
      * only being added if it does not already exist.
@@ -257,11 +260,6 @@
     docID = documentId;
     cid = containerId;
     content = new Content();
-    protected void finalize() throws XmlException {
-     metaData.clear();
-     content.clear();
     protected void copy(XmlDocument o) throws XmlException {
@@ -359,6 +357,10 @@
     protected void setEventWriter(long writer){
     eventWriter = writer;
+    }
+   
+    protected Content getEmptyContent() {
+         return new Content();
     class Content {
diff -r 3ea6fcd222af src/java/com/sleepycat/dbxml/XmlValue.java
--- a/src/java/com/sleepycat/dbxml/XmlValue.java     Wed Nov 05 12:39:38 2008 -0500
+++ b/src/java/com/sleepycat/dbxml/XmlValue.java     Tue Nov 18 10:11:16 2008 -0500
@@ -9,6 +9,8 @@
package com.sleepycat.dbxml;
import java.util.*;
+
+import com.sleepycat.dbxml.XmlDocument.Content;
public class XmlValue {
     protected Value value;
@@ -69,7 +71,10 @@
     public XmlValue(XmlDocument document) throws XmlException
-     XmlValue xmlvalue = HelperFunctions.createDocumentValue(document);
+    Content con = document.content;
+    document.content = document.getEmptyContent(); //Prevents the content from being consumed
+    XmlValue xmlvalue = HelperFunctions.createDocumentValue(document);
+    document.content = con;
     valueType = xmlvalue.getType();
     value = new NodeValue((NodeValue)xmlvalue.value);
     ((NodeValue)value).setDocument(document);
diff -r 3ea6fcd222af src/java/dbxml_java_wrap.cpp
--- a/src/java/dbxml_java_wrap.cpp     Wed Nov 05 12:39:38 2008 -0500
+++ b/src/java/dbxml_java_wrap.cpp     Tue Nov 18 10:11:16 2008 -0500
@@ -1516,10 +1516,8 @@
         XmlValue value((XmlValue::Type)type, v);
SWIGINTERN XmlInputStream *HelperFunctions_getContentAsXmlInputStream(XmlDocument &doc){
-         XmlEventReader &reader = doc.getContentAsEventReader();
-         doc.setContentAsEventReader(reader);
-         return doc.getContentAsXmlInputStream();
+          return doc.getContentAsXmlInputStream();
+      }
SWIGINTERN XmlEventReader &HelperFunctions_getContentAsEventReader(XmlDocument &doc){
         return doc.getContentAsEventReader();
     }

Similar Messages

  • Can we create multiple billing document from delivery with single line item

    can we create multiple billing document from delivery with single line item

    Hi
    Please check the link
    [can v create multiple billing document from delivery with single line item]
    and as Lakshmi said, check the forum before posting an issue.
    Regards
    AA

  • Can v create multiple billing document from delivery with single line item

    can v create multiple billing document from delivery with single line item

    Dear Sandesh
    Go to VOV7, select your item category.  In this maintain K  for Billing Relevance
    Now go to VF01, give the delivery number and do not press Enter.  Instead click on Selection list on the next screen, select the items you want to bill and click copy and continue if necessary
    thanks
    G. Lakshmipathi

  • How can I create a XML document from a DOM?

    Hello,
    I'm using the parser for C, version 2 in the DOM modus. How can I dump the object model to a (XML) string after changing some field?
    Do I need to create my own function or is there a function in the DOM interface??

    You need to create your own function. The Java XML parser has such a function
    and we'll probably add one in a future release as well.
    Oracle XML Team

  • How can I create a single order from multiple quotations?

    How can I create a single order from multiple quotations that I have created by the transaction VA21 ?
    Thanks in advance for the answers.

    hi
    Go to transaction: /nva01
    Enter order type : ZOR
    Sale org :xxxx
    Dist.channel:xx
    Division :xx
    Press enter
    Click on “Sale document” and select Create with reference
    Then enter 1st quotation number & click on “COPY” or “Selection list”. Then click on “Copy “.Then all line items which belong to quoation1 copy to order.
    Then,
    Click on “Sale document” and select Create with reference
    Then enter 2nd quotation number & click on “COPY” or “Selection list”. Then click on “Copy “.Then all line items which belong to quoation2 copy to order.
    Then,
    Click on “Sale document” and select Create with reference
    Then enter 3rd quotation number & click on “COPY” or “Selection list”. Then click on “Copy “.Then all line items which belong to quoation3 copy to order.
    Now save the sale document.
    Kindly give reward points
    Edited by: WISH on Mar 19, 2008 2:25 PM

  • How to create an XML document from a String.

    Can anyone help,
         In the Microsoft XML Document DOM there is a load function load(string) which will create an XML document, but now we are switching to Java and I do not know how to create and XML document from a string, this string �xml document� is passed to my program from a webservice and I need to read several xml elements form it in a web server.
    This string is a well formatted XML document:
    <?xml version="1.0" encoding="UTF-8"?>
    <Countries NumberOfRecords="1" LanguageID="en-us">
         <Country>
              <CountryCode>AU</CountryCode>
              <CountryName>AUSTRALIA</CountryName>
         </Country>
    </Countries>

    Thanks PC!
    I made it work using:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    factory.setIgnoringComments(true); // We want to ignore comments
    // Now use the factory to create a DOM parser
    DocumentBuilder parser = factory.newDocumentBuilder();
    //TransformThisStringBuffer is a string buffer wich contain the 'XML document (String)'
    InputStream in = new ByteArrayInputStream(TransformThisStringBuffer.toString().getBytes());
    // Parse the InputStream and build the document
    Document document = parser.parse(in);
    But which one is faster InputSource or InputStream, were would you put the "new InputSource(new StringReader(yourString))" in the above code?

  • Error when creating link to documents from material

    Hi all,
    while creating the purchase order the error message "Error when creating link to documents from material 61260224060" is displayed.
    why this error message is displayed.?
    Regards,
    GaneshRaja

    Hello Ganesh
    Please check material master - view 'Bases data 2'.
    There is checkbox 'No link'. You can activate this checkbox if you are not storing any drawing/designe docuemnt for this material.
    Try to do this and check out again.....
    If this helps you in resolving your issue, i would appreciate if you reward the answer with suitable points.
    Best Regards
    Avinash

  • Create an XML document from a HTML form???

    Good morning, is it possible to create an XML document from a HTML form
    if yes, can someone tell me how to proceed exactely, I would be very thankful!

    Hi,
    A very simple intro at this link. Apologies for anything unclear.
    http://cswww.essex.ac.uk/TechnicalGroup/TechnicalHelp/xmlCreate.htm
    best
    kev

  • Create draft invoice document from a sales order

    When i create an invoice document from a draft invoice document from a sales order, this invoce is linked to the order sales.
    Sorry for my english, i hope you can understand

    It would be difficult to know what question do you have.  Try to ask question.  Your English is not bad at all.
    Thanks,
    Gordon

  • How do you create a PDF document from excel???

    How do you create a PDF document from excel???

    Hi Kwasi Debra,
    You might need to sign up at "https://cloud.acrobat.com/" using your Adobe ID credentials.
    Then, select 'Create PDF' tab and click on 'Select PDF files to export' option.
    Upload your excel file and it will get converted to PDF format within a couple of minutes.
    Later, you can even download the converted file onto your system.
    Please try in the same manner and check.
    Regards,
    Anubha

  • Can i create a single image from multiple images in lightroom?

    Can i create a single image from multiple images in lightroom?

    Like a panorama, a composite or focus stack? Have you tried the Lightroom forum?
    Photoshop Lightroom

  • Why can't I print a document from iphone5 to hp wireless printer?

    Why can't I print a document from iphone5 to hp wireless printer?

    Try the following steps.
    Power off the printer.
    Reset the phone by holding the sleep/wake and home buttons together until you see the Apple logo and then release. The phone will reboot.
    Power cycle your router. Disconnect it from power for about 30 seconds and then power it back on.
    Once it has completed the reboot, then power the printer back on and make sure it connects to the wi-fi network
    Open the content on the phone that you want to print and attempt printing it again.
    If that does not do it, then check to see if there is any newer firmware for the printer from HP.

  • Can I create a shared photostream from my pc?

    I know I can upload photos from my PC to My Photostream, but I want to create a Shared Photostream (album) with photos from my PC.  It seems I cannot create an individual Shared Photostream album on my PC, and upload pictures to it.  I can only create a Shared Photostream from my iPhone, and upload photos to it from my iPhone.  Am I doing something wrong?
    The problem with My Photostream is the photos there will get bumped in time, with pictures taken by my iPhone.  I want to keep the photos in a Shared Photostream (album) so as to play them on my Apple TV.
    What can I do?
    Thanks!!!

    Thanks so much.  I clicked the New photo stream link at the top and was able to make an album of photos to display on my Apple TV, just as desired.  Only problem now is that the Random Theme selection in Apple TV does not rotate amongst the various themes, it just sticks on one, unlike the Random Theme selection in Ken Burns or Classic selection choices at the bottom of the list which does rotate.  If you know anything about this, please let me know.  Meanwhile thanks again to set me straight on the first tip!

  • How can I create an audio CD from the audio only portion of my iMovie?

    Hello, I brought in about 50 min of Digital video into iMovie, I separated (split) the audio from the video, I unlocked the audio, I deleted the video, and now I want to just create an audio CD from the audio that is left.
    Can I do this? and if yes how? If I can not, how can I create an Audio CD from on my G5 off a tape on my digital camcorder?
    Any help would be apprecaited.

    This is how:
    Go to:
    'File'
    'Share'
    'Quicktime'
    'Expert Settings'
    'Audio as AIFF' or pick your brand of compression.
    Drag and drop the resulting file into iTunes.
    Enjoy!
    P.S. - You didn't need to delete the video but I think that'll be okay.

  • How can I download a .pdf document from a web link without Adobe Reader starting automatically and i

         How can I download a .pdf document from a web link without Adobe Reader starting automatically and preempting the download?                         

    That depends on your operating system and browser.  On Windows, e.g. using Firefox, you right-click on the link, then select 'Save link as...'.

Maybe you are looking for

  • How to give dynamic name for csv export files?

    Hi, how we can give dynamic file name for each csv export file? ex(&item_name.csv) I am using apex 4.1 and IE 6, thanks in advance regards Chandran

  • Form Alignment issue in table: Custom submit button

    Yesterday as I was putting together a "check availability" form within a horizontal table, I ran into difficulties getting the form to vertically align in the middle, it kept aligning to the top. I was able to correct the problem using the following

  • Whitespace problems in flat output file

    hello, I wonder if anyone can help me please? I am trying to spool a flat csv (.txt) file from a query which returns a very large dataset. The problem I am having is that I can not seem to fit everything on one row. There is a lot of whitespace being

  • Parameter not being set in before parameter form trigger

    I am running 10g reports over the web and have a problem with some parameters. I have a User parameter which I set in the BEFORE-PARAMETER-FORM trigger. This parameter is not displayed on the parameter form because it shouldn't ever be changed by a u

  • Local URL in WebService address and WSDL file

    Hi everyone, I developed, built and deployed my webservice on a machine. To reach the webservice from the web it has a specific IP (binded to point to a local IP) , but when i access to it the URL inside the webservice address, the reference to the w