Project

Profile

Help

Nested Collections & Xpath s9api

Added by Anonymous almost 16 years ago

Legacy ID: #5757489 Legacy Poster: julianhall (julianhall)

Hi, I'm attempting to replace a DataSet/DataTable implementation in our application for performance reasons... Our DataTable xml structure (don't ask why) is as follows: <DataTable> <r><h>fieldName 1</h>...<h>fieldName N</h></r> <r><d> value1 </d>...<d> valueN </h></r> ... <r><d> value1 </d>...<d> valueN </h></r> </DataTable> and our DataSet structure can contain many DataTables: <DataSet> <DataTable>* </DataSet When I create a DataTable instance from a file i use the document builder to read the document and save the DataTable node: tableNode = (XdmNode)tableDocument.axisIterator(Axis.CHILD).next(); I want to select a field value I run the following xpath query on the tableNode: r[$rowNum+2]/d[index-of( //DataTable/r/h/text() , $fieldName)]/text() and everything is fine. I can just as easily run this query as well and it works: r[$rowNum+2]/d[index-of( //r/h/text() , $fieldName)]/text() My real problem is that when I try to use the same xpath functions on a DataTable XdmNode taken from a DataSet .. i always get a null value? Here are my methods that i'm using: public XdmValue executeXPath(String query, XdmItem item, Map<QName, XdmValue> values) throws SaxonApiException, IOException { XPathSelector selector = getXPathSelector(query,values); selector.setContextItem(item); setVariables(values, selector); return selector.evaluate(); } private XPathSelector getXPathSelector(String query, Map<QName, XdmValue> values) throws SaxonApiException { XPathCompiler xpc = _processor.newXPathCompiler(); declareVariables(values,xpc); XPathExecutable exp = xpc.compile(getFileContents(query)); XPathSelector selector = exp.load(); return selector; } Any help on this would be greatly appreciated. Thanks, Julian


Replies (2)

RE: Nested Collections &amp; Xpath s9api - Added by Anonymous almost 16 years ago

Legacy ID: #5757928 Legacy Poster: Michael Kay (mhkay)

If there are multiple DataTable elements in your document then //DataTable is going to select them all, and //DataTable/r/h/text() will be a sequence containing all the field names from all the tables, not just the current table. Change //DataTable to ancestor::DataTable so you only select the one that's relevant. Or better still, bind a variable to the DataTable node that you are selecting within.

RE: Nested Collections &amp; Xpath s9api - Added by Anonymous almost 16 years ago

Legacy ID: #5757959 Legacy Poster: julianhall (julianhall)

Michael - thank you! That simple changed gave me 100% pass rate on all my unit tests! Regards, Julian

    (1-2/2)

    Please register to reply