[bdbxml] Simple Xpath/Xqueries don't work?

"Antony Grinyer" <antony.grinyer-TjPRh57ScDpaa/[email protected]> Fri, 5 Aug 2005 17:27:09 +0100
Newsgroups gmane.comp.db.dbxml.general
Message-ID <989E1989F3130042879B902D1758421612D541@msxmigration.cswgroup.local>
I have a very basic XML instance stored in a container called
Sample.bdbxml. The structure is:

<documents>
	<publication>
		<metadata>
			<title>C++ in a Nutshell</title>
		</metadata>
		<description>Information about C++</description>
	</publication>
	<publication>
		<metadata>
			<title>Java  in a Nutshell</title>
		</metadata>
		<description>Information about Java</description>
	</publication>
</documents>

I have a simple HTML form which displays a text area which I use to add
Xpath/XQuery expressions. This form is submitted to some code which
opens the container and runs the query. Here's the method content which
runs the query:

    StringBuffer resultsBuffer = new StringBuffer();
    try
    {
      XmlQueryContext context = xmlManager.createQueryContext();   
      XmlQueryExpression qe = xmlManager.prepare(xQueryExpr, context);
      XmlResults results = qe.execute(context);
      while (results.hasNext())
      {
        XmlValue value = results.next();
        resultsBuffer.append(value.asString());
      }
    }
    catch (XmlException e)
    {
      throw new BDBXMLException("Xml exception in BDBXMLQueryServiceImpl
method retrieveDocumentsByXQuery | " + e.toString() + ", error code " +
e.getErrno());
    }
    return resultsBuffer.toString();


The xQueryExpr variable is the Xpath/XQuery expression passed into the
method.  Now, whenever I try running any queries to get the publication
title from the XML, BDBXML complains about syntax even when I use the
examples in the documentation. I have tried:

/documents/publication/metadata/title

//publication/metadata/title

//*/publication/metadata/title

collection('Sample.bdbxml')//publication/metadata/title

distinct-values(/documents/publication/metadata/title)


...and none of them work, I just get this error all the time:

com.sleepycat.dbxml.XmlException: Error: An attempt to navigate when the
Context Item was not a node was made [err:XP0020], errcode =
XPATH_EVALUATION_ERROR, error code 0

Any ideas please?
Thanks,
Ant





------------------------------------------
To remove yourself from this list, send an
email to [email protected]