org.xmldb.api.modules

Interface XPathQueryService

public interface XPathQueryService extends Service

XPathQueryService is a Service that enables the execution of XPath queries within the context of a Collection or against a single XML Resource stored in the Collection.
Method Summary
voidclearNamespaces()
Removes all namespace mappings stored in the internal namespace map.
StringgetNamespace(String prefix)
Returns the URI string associated with prefix from the internal namespace map.
ResourceSetquery(String query)
Run an XPath query against the Collection.
ResourceSetqueryResource(String id, String query)
Run an XPath query against an XML resource stored in the Collection associated with this service.
voidremoveNamespace(String prefix)
Removes the namespace mapping associated with prefix from the internal namespace map.
voidsetNamespace(String prefix, String uri)
Sets a namespace mapping in the internal namespace map used to evaluate queries.

Method Detail

clearNamespaces

public void clearNamespaces()
Removes all namespace mappings stored in the internal namespace map.

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

getNamespace

public String getNamespace(String prefix)
Returns the URI string associated with prefix from the internal namespace map. If prefix is null or empty the URI for the default namespace will be returned. If a mapping for the prefix can not be found null is returned.

Parameters: prefix The prefix to retrieve from the namespace map.

Returns: The URI associated with prefix

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

query

public ResourceSet query(String query)
Run an XPath query against the Collection. The XPath will be applied to all XML resources stored in the Collection. The result is a ResourceSet containing the results of the query. Any namespaces used in the query string will be evaluated using the mappings setup using setNamespace.

Parameters: query The XPath query string to use.

Returns: A ResourceSet containing the results of the query.

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

queryResource

public ResourceSet queryResource(String id, String query)
Run an XPath query against an XML resource stored in the Collection associated with this service. The result is a ResourceSet containing the results of the query. Any namespaces used in the query string will be evaluated using the mappings setup using setNamespace.

Parameters: query The XPath query string to use. id The id of the document to run the query against.

Returns: A ResourceSet containing the results of the query.

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

removeNamespace

public void removeNamespace(String prefix)
Removes the namespace mapping associated with prefix from the internal namespace map. If prefix is null or empty the mapping for the default namespace will be removed.

Parameters: prefix The prefix to remove from the namespace map. If prefix is null or empty the mapping for the default namespace will be removed.

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

setNamespace

public void setNamespace(String prefix, String uri)
Sets a namespace mapping in the internal namespace map used to evaluate queries. If prefix is null or empty the default namespace is associated with the provided URI. A null or empty uri results in an exception being thrown.

Parameters: prefix The prefix to set in the map. If prefix is empty or null the default namespace will be associated with the provided URI. uri The URI for the namespace to be associated with prefix.

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
TODO: probably need some special error here.