## org.xmldb.api.modules
Interface XMLResource

All Superinterfaces:
  Resource

All Known Implementing Classes:
  LocalXMLResource, RemoteXMLResource

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 on `String` content.

Field Summary
`static java.lang.String` `RESOURCE_TYPE`

Method Summary
`org.w3c.dom.Node` `getContentAsDOM()` Returns the content of the `Resource` as a DOM Node.
`void` `getContentAsSAX(org.xml.sax.ContentHandler handler)` Allows you to use a `ContentHandler` to parse the XML data from the database for use in an application.
`java.lang.String` `getDocumentId()` Returns the unique id for the parent document to this `Resource` or null if the `Resource` does not have a parent document.
`boolean` `getSAXFeature(java.lang.String feature)` Returns current setting of a SAX feature that will be used when this `XMLResource` is used to produce SAX events (through the getContentAsSAX() method)
`void` `setContentAsDOM(org.w3c.dom.Node content)` Sets the content of the `Resource` using a DOM Node as the source.
`org.xml.sax.ContentHandler` `setContentAsSAX()` Sets the content of the `Resource` using a SAX `ContentHandler`.
`void` `setSAXFeature(java.lang.String feature, boolean value)` Sets a SAX feature that will be used when this `XMLResource` is used to produce SAX events (through the getContentAsSAX() method)

Methods inherited from interface org.xmldb.api.base.Resource
`getContent, getId, getParentCollection, getResourceType, setContent`

Field Detail

### RESOURCE_TYPE

    public static final java.lang.String RESOURCE_TYPE

See Also:
  Constant Field Values

Method Detail

### getDocumentId

    public java.lang.String getDocumentId()
                                   throws XMLDBException

  Returns the unique id for the parent document to this `Resource` or null if the `Resource` does not have a parent document. `getDocumentId()` is typically used with `Resource` instances retrieved using a query. It enables accessing the parent document of the `Resource` even if the `Resource` is a child node of the document. If the `Resource` was not obtained through a query then `getId()` and `getDocumentId()` will return the same id.

  Returns:
    the id for the parent document of this `Resource` or null if there is no parent document for this `Resource`.
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.

### getContentAsDOM

    public org.w3c.dom.Node getContentAsDOM()
                                     throws XMLDBException

  Returns the content of the `Resource` as a DOM Node.

  Returns:
    The XML content as a DOM `Node`
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.

### setContentAsDOM

    public void setContentAsDOM(org.w3c.dom.Node content)
                         throws XMLDBException

  Sets the content of the `Resource` using a DOM Node as the source.

  Parameters:
    `content` - The new content value
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.INVALID_RESOURCE` if the content value provided is null.
    `ErrorCodes.WRONG_CONTENT_TYPE` if the content provided in not a valid DOM `Node`.

### getContentAsSAX

    public void getContentAsSAX(org.xml.sax.ContentHandler handler)
                         throws XMLDBException

  Allows you to use a `ContentHandler` to parse the XML data from the database for use in an application.

  Parameters:
    `handler` - the SAX `ContentHandler` to use to handle the `Resource` content.
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.INVALID_RESOURCE` if the `ContentHandler` provided is null.

### setContentAsSAX

    public org.xml.sax.ContentHandler setContentAsSAX()
                                               throws XMLDBException

  Sets the content of the `Resource` using a SAX `ContentHandler`.

  Returns:
    a SAX `ContentHandler` that can be used to add content into the `Resource`.
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.

### setSAXFeature

    public void setSAXFeature(java.lang.String feature,
                              boolean value)
                       throws org.xml.sax.SAXNotRecognizedException,
                              org.xml.sax.SAXNotSupportedException

  Sets a SAX feature that will be used when this `XMLResource` is 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`
    `org.xml.sax.SAXNotSupportedException`

### getSAXFeature

    public boolean getSAXFeature(java.lang.String feature)
                          throws org.xml.sax.SAXNotRecognizedException,
                                 org.xml.sax.SAXNotSupportedException

  Returns current setting of a SAX feature that will be used when this `XMLResource` is 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`
    `org.xml.sax.SAXNotSupportedException`

Copyright (C) Wolfgang Meier. All rights reserved.