|
From: Alister P. <gsp...@gm...> - 2012-08-11 06:33:18
|
Hi,
I'd really appreciate some help in understanding the difference between in-memory elements (directly constructed elements in an xquery) and elements stored in the database and represented by NodeProxy.
The problem (again) is in the AbstractCompressFunction which behaves differently depending on whether the "<entry>" is directly constructed, or stored in the database.
In the compressElement method, this statement:
System.out.println("*** COUNT: " + element.getChildNodes().getLength() + ", E: " + element + " --- " + element.getChildNodes());
produces
*** COUNT: 1, E: in-memory#element {entry} {in-memory#attribute {name} {test-doc.xml} in-memory#attribute {type} {uri} in-memory#text {/test/test-doc.xml} } --- [in-memory#text {/test/test-doc.xml} ]
for a directly constructed element,
and this:
*** COUNT: 3, E: <entry name="test-doc.xml" type="uri">/test/test-doc.xml</entry> --- [ name="test-doc.xml", type="uri", /test/test-doc.xml]
for an <entry> stored in the database.
In the compressElement method, the second case throws an error because the child count is >1.
Am I using NodeProxy incorrectly? Should I cast to something other than Element?
The first case is the result of this patch:
Index: extensions/modules/src/org/exist/xquery/modules/compression/AbstractCompressFunction.java
===================================================================
--- extensions/modules/src/org/exist/xquery/modules/compression/AbstractCompressFunction.java (revision 16905)
+++ extensions/modules/src/org/exist/xquery/modules/compression/AbstractCompressFunction.java (working copy)
@@ -37,6 +37,7 @@
import org.exist.dom.DefaultDocumentSet;
import org.exist.dom.DocumentImpl;
import org.exist.dom.MutableDocumentSet;
+import org.exist.dom.NodeProxy;
import org.exist.security.PermissionDeniedException;
import org.exist.storage.lock.Lock;
import org.exist.storage.serializers.Serializer;
@@ -123,6 +124,12 @@
Element element = (Element) item;
compressElement(os, element, useHierarchy, stripOffset);
}
+ else if (item instanceof NodeProxy)
+ {
+ NodeProxy nodeproxy = (NodeProxy) item;
+ Element element = (Element) nodeproxy.getNode();
+ compressElement(os, element, useHierarchy, stripOffset);
+ }
else
{
compressFromUri(os, ((AnyURIValue)item).toXmldbURI(), useHierarchy, stripOffset, "", null);
@@ -206,6 +213,7 @@
if(!(element.getNodeName().equals("entry") || element.getNamespaceURI().length() > 0))
throw new XPathException(this, "Item must be type of xs:anyURI or element enry.");
+ System.out.println("*** CHILDNODES COUNT: " + element.getChildNodes().getLength() + ", E: " + element + " --- " + element.getChildNodes());
if(element.getChildNodes().getLength() > 1)
throw new XPathException(this, "Entry content is not valid XML fragment.");
|