Package org.xmldb.api.modules
Interface XMLResource
-
- All Superinterfaces:
java.lang.AutoCloseable,Resource
public interface XMLResource extends Resource
Provides access to XML resources stored in the database. An XMLResource can be accessed either as text XML or via the DOM or SAX APIs. The default behavior for getContent and setContent is to work with XML data as text so these methods work onStringcontent.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description org.w3c.dom.NodegetContentAsDOM()Returns the content of theResourceas a DOM Node.voidgetContentAsSAX(org.xml.sax.ContentHandler handler)Allows you to use aContentHandlerto parse the XML data from the database for use in an application.java.lang.StringgetDocumentId()Returns the unique id for the parent document to thisResourceor null if theResourcedoes not have a parent document.default ResourceTypegetResourceType()Returns the resource type for this Resource.booleangetSAXFeature(java.lang.String feature)Returns current setting of a SAX feature that will be used when thisXMLResourceis used to produce SAX events (through the getContentAsSAX() method)voidsetContentAsDOM(org.w3c.dom.Node content)Sets the content of theResourceusing a DOM Node as the source.org.xml.sax.ContentHandlersetContentAsSAX()Sets the content of theResourceusing a SAXContentHandler.voidsetSAXFeature(java.lang.String feature, boolean value)Sets a SAX feature that will be used when thisXMLResourceis used to produce SAX events (through the getContentAsSAX() method)voidsetXMLReader(org.xml.sax.XMLReader xmlReader)Sets the external XMLReader to use when doing content handler operations.-
Methods inherited from interface org.xmldb.api.base.Resource
close, getContent, getContentAsStream, getCreationTime, getId, getLastModificationTime, getParentCollection, isClosed, setContent
-
-
-
-
Method Detail
-
getResourceType
default ResourceType getResourceType()
Description copied from interface:ResourceReturns the resource type for this Resource. XML:DB defined resource types are: XMLResource - all XML data stored in the database BinaryResource - Binary blob data stored in the database- Specified by:
getResourceTypein interfaceResource- Returns:
- the resource type for the Resource.
-
getDocumentId
java.lang.String getDocumentId() throws XMLDBExceptionReturns the unique id for the parent document to thisResourceor null if theResourcedoes not have a parent document.getDocumentId()is typically used withResourceinstances retrieved using a query. It enables accessing the parent document of theResourceeven if theResourceis a child node of the document. If theResourcewas not obtained through a query thengetId()andgetDocumentId()will return the same id.- Returns:
- the id for the parent document of this
Resourceor null if there is no parent document for thisResource. - Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
getContentAsDOM
org.w3c.dom.Node getContentAsDOM() throws XMLDBExceptionReturns the content of theResourceas a DOM Node.- Returns:
- The XML content as a DOM
Node - Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
setContentAsDOM
void setContentAsDOM(org.w3c.dom.Node content) throws XMLDBExceptionSets the content of theResourceusing a DOM Node as the source.- Parameters:
content- The new content value- Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.ErrorCodes.INVALID_RESOURCEif the content value provided is null.ErrorCodes.WRONG_CONTENT_TYPEif the content provided in not a valid DOMNode.
-
getContentAsSAX
void getContentAsSAX(org.xml.sax.ContentHandler handler) throws XMLDBExceptionAllows you to use aContentHandlerto parse the XML data from the database for use in an application.- Parameters:
handler- the SAXContentHandlerto use to handle theResourcecontent.- Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.ErrorCodes.INVALID_RESOURCEif theContentHandlerprovided is null.
-
setContentAsSAX
org.xml.sax.ContentHandler setContentAsSAX() throws XMLDBExceptionSets the content of theResourceusing a SAXContentHandler.- Returns:
- a SAX
ContentHandlerthat can be used to add content into theResource. - Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
setSAXFeature
void setSAXFeature(java.lang.String feature, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionSets a SAX feature that will be used when thisXMLResourceis used to produce SAX events (through the getContentAsSAX() method)- Parameters:
feature- Feature name. Standard SAX feature names are documented at http://sax.sourceforge.net/.value- Set or unset feature- Throws:
org.xml.sax.SAXNotRecognizedException- if the feature is not recognized.org.xml.sax.SAXNotSupportedException- if the feature is not supported.
-
getSAXFeature
boolean getSAXFeature(java.lang.String feature) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionReturns current setting of a SAX feature that will be used when thisXMLResourceis used to produce SAX events (through the getContentAsSAX() method)- Parameters:
feature- Feature name. Standard SAX feature names are documented at http://sax.sourceforge.net/.- Returns:
- whether the feature is set
- Throws:
org.xml.sax.SAXNotRecognizedException- if the feature is not recognized.org.xml.sax.SAXNotSupportedException- if the feature is not supported.
-
setXMLReader
void setXMLReader(org.xml.sax.XMLReader xmlReader)
Sets the external XMLReader to use when doing content handler operations.- Parameters:
xmlReader- the XMLReader
-
-