Hi Dean, say the username is "steve" the result of your current XQuery
expression is:
"for $x in //aRecord
where $x/id = steve
return $x"
"steve" must be defined as "steve" or xs:string("steve"), etc otherwise it
an XQuery exception will occur.
So either inline this into your query as appropriate.
Another thing to point out Dean, once you solve this error you will only
run into another.
"ResourceIterator results = resultSet.getIterator();"
This will return you a result set of the query,
e.g. just the root nodes, this will not return you the resource ids, so
the XML:DB API
will not know which records you actually want to delete based on this query.
If you insist on using XML:DB without Sedna UPDATE language, then try the
following:
// ---------
String username = "steve";
XQueryService xqs = (XQueryService)bookings.getService("XQueryService",
"1.0");
xqs.declareVariable("username", username);
ResourceSet rs = xqs.query("for $x in //booking where $x/id = $username
return document-uri(root($x))");
ResourceIterator iter = rs.getIterator();
while(iter.hasMoreResources())
{
String documentId = iter.nextResource().toString();
Resource res = bookings.getResource(documentId);
bookings.removeResource(res);
}
bookings.close();
// ---------
I actually suggest that you use Sedna UPDATE language to complete this task,
the method described above is no way near as efficient, because it involves:
1. An XQuery
2. Processing Results
3. Retrieving Documents
4. Deleting Documents
Where a Sedna UPDATE statement would be just:
1. Delete documents based on requirements.
To execute a Sedna UPDATE statement, use either:
SednaUpdateService.update(String sednaUpdateStatement);
or
XQueryService.execute(CompiledExpression expression);
or
XQueryService.query(String sednaUpdateStatement);
Regards,
Charles
> I'm trying to remove an xml document from a collection, but when it
> runs, I get the following error message:
>
> XMLDB Error: 1:SEDNA Message: ERROR XPDY0002 It is a dynamic error if
> evaluation of an expression relies on some part of the dynamic context
> that has not been assigned a value.
>
>
> This is the structure of the documents in the collection:
>
> <?xml version="1.0" standalone="yes"?>
> <booking>
> <id>FRED125</id>
> <name>Fred Bloggs</name>
> <source>MEL</source>
> </booking>
>
> What I want to do is search for documents with "FRED125" in the id
> element (passed in as "username" in the query), and nuke them:
>
> // Delete from database
> try
> {
> registerXMLDBDriver();
> Collection bookings =
> DatabaseManager.getCollection(databaseURI, databaseUsername,
> databasePassword);
>
> String query = "for $x in //aRecord \n"+
> "where $x/id = " + username +"\nreturn $x";
> XQueryService service =
> (XQueryService)bookings.getService("XQueryService", "1.0");
> ResourceSet resultSet =
> service.query(query);
> ResourceIterator results =
> resultSet.getIterator();
> while (results.hasMoreResources())
> {
> XMLResource resource = (XMLResource)
> results.nextResource();
> bookings.removeResource(resource);
> }
>
> // Close up shop.
> bookings.close();
> }
>
>
> I know I've probably done something silly with the syntax of the query
> string itself. Advice please?
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Sedna-discussion mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sedna-discussion
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Sedna-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sedna-discussion