public class DOMHandle extends BaseHandle<InputStream,OutputStreamSender> implements OutputStreamSender, BufferableHandle, ContentHandle<Document>, XMLReadHandle, XMLWriteHandle, StructureReadHandle, StructureWriteHandle
A DOM Handle represents XML content as a DOM document for reading or writing.
UNKNOWN_LENGTH| Constructor and Description |
|---|
DOMHandle()
Zero-argument constructor.
|
DOMHandle(Document content)
Initializes the handle with a DOM document for the content.
|
| Modifier and Type | Method and Description |
|---|---|
XPathExpression |
compileXPath(String xpathExpression)
Compile an XPath string expression for efficient evaluation later.
|
<T> T |
evaluateXPath(String xpathExpression,
Class<T> as)
Evaluate a string XPath expression against the retrieved document.
|
<T> T |
evaluateXPath(String xpathExpression,
Node context,
Class<T> as)
Evaluate a string XPath expression relative to a node such as a node returned by a previous XPath expression.
|
<T> T |
evaluateXPath(XPathExpression xpathExpression,
Class<T> as)
Evaluate a compiled XPath expression against the retrieved document.
|
<T> T |
evaluateXPath(XPathExpression xpathExpression,
Node context,
Class<T> as)
Evaluate a compiled XPath expression relative to a node such as a node returned by a previous XPath expression.
|
void |
fromBuffer(byte[] buffer)
Sets the content of the handle by copying from a byte array buffer encoded in UTF-8.
|
Document |
get()
Returns the DOM document for the content.
|
DocumentBuilderFactory |
getFactory()
Returns the factory for building DOM documents.
|
LSResourceResolver |
getResolver()
Returns the resolver for resolving references while parsing the document.
|
XPath |
getXPathProcessor()
Get the processor used to evaluate XPath expressions.
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a DOMHandle instance for a DOM document.
|
void |
set(Document content)
Assigns a DOM document as the content.
|
void |
setFactory(DocumentBuilderFactory factory)
Specifies the factory for building DOM documents.
|
void |
setFormat(Format format)
Restricts the format to XML.
|
void |
setResolver(LSResourceResolver resolver)
Specifies the resolver for resolving references while parsing the document.
|
void |
setXPathProcessor(XPath xpathProcessor)
Specifies the processor used to evaluate XPath expressions against the document.
|
byte[] |
toBuffer()
Copies the content of the handle to a byte array buffer encoded in UTF-8.
|
String |
toString()
Returns the DOM document as an XML string.
|
DOMHandle |
with(Document content)
Assigns a DOM document as the content and returns the handle as a fluent convenience.
|
DOMHandle |
withMimetype(String mimetype)
Specifies the mime type of the content and returns the handle as a fluent convenience.
|
void |
write(OutputStream out)
Implements a callback to write content to the provided output stream for sending to the database server.
|
getByteLength, getFormat, getMimetype, getServerTimestamp, setByteLength, setMimetype, setServerTimestamppublic DOMHandle()
Zero-argument constructor.
public DOMHandle(Document content)
Initializes the handle with a DOM document for the content.
content - a DOM documentpublic static ContentHandleFactory newFactory()
Creates a factory to create a DOMHandle instance for a DOM document.
public LSResourceResolver getResolver()
Returns the resolver for resolving references while parsing the document.
public void setResolver(LSResourceResolver resolver)
Specifies the resolver for resolving references while parsing the document.
resolver - the reference resolverpublic Document get()
Returns the DOM document for the content.
get in interface ContentHandle<Document>public void set(Document content)
Assigns a DOM document as the content.
set in interface ContentHandle<Document>content - a DOM documentpublic DOMHandle with(Document content)
Assigns a DOM document as the content and returns the handle as a fluent convenience.
content - a DOM documentpublic void setFormat(Format format)
Restricts the format to XML.
setFormat in interface ContentDescriptorsetFormat in class BaseHandle<InputStream,OutputStreamSender>format - the format of the contentpublic DOMHandle withMimetype(String mimetype)
Specifies the mime type of the content and returns the handle as a fluent convenience.
mimetype - the mime type of the contentpublic void fromBuffer(byte[] buffer)
BufferableHandleSets the content of the handle by copying from a byte array buffer encoded in UTF-8.
fromBuffer in interface BufferableHandlebuffer - the byte arraypublic byte[] toBuffer()
BufferableHandleCopies the content of the handle to a byte array buffer encoded in UTF-8.
toBuffer in interface BufferableHandlepublic String toString()
Returns the DOM document as an XML string.
public DocumentBuilderFactory getFactory() throws ParserConfigurationException
Returns the factory for building DOM documents.
ParserConfigurationException - if it occurs while initializing the new factorypublic void setFactory(DocumentBuilderFactory factory)
Specifies the factory for building DOM documents.
factory - the document factorypublic XPath getXPathProcessor()
Get the processor used to evaluate XPath expressions. You might get the XPath processor to configure it. For instance, you can configure the XPath processor to declare namespace bindings or to set a function or variable resolver.
EditableNamespaceContextpublic void setXPathProcessor(XPath xpathProcessor)
Specifies the processor used to evaluate XPath expressions against the document.
xpathProcessor - the XPath expression processorpublic <T> T evaluateXPath(String xpathExpression, Class<T> as) throws XPathExpressionException
Evaluate a string XPath expression against the retrieved document. An XPath expression can return a Node or subinterface such as Element or Text, a NodeList, or a Boolean, Number, or String value.
T - the type to returnxpathExpression - the XPath expression as a stringas - the type expected to be matched by the xpathXPathExpressionException - if xpathExpression cannot be evaluatedpublic <T> T evaluateXPath(String xpathExpression, Node context, Class<T> as) throws XPathExpressionException
Evaluate a string XPath expression relative to a node such as a node returned by a previous XPath expression. An XPath expression can return a Node or subinterface such as Element or Text, a NodeList, or a Boolean, Number, or String value.
T - the type to returnxpathExpression - the XPath expression as a stringcontext - the node for evaluating the expressionas - the type expected to be matched by the xpathXPathExpressionException - if xpathExpression cannot be evaluatedpublic XPathExpression compileXPath(String xpathExpression) throws XPathExpressionException
Compile an XPath string expression for efficient evaluation later.
xpathExpression - the XPath expression as a stringXPathExpressionException - if xpathExpression cannot be compiledpublic <T> T evaluateXPath(XPathExpression xpathExpression, Class<T> as) throws XPathExpressionException
Evaluate a compiled XPath expression against the retrieved document. An XPath expression can return a Node or subinterface such as Element or Text, a NodeList, or a Boolean, Number, or String value.
T - the type to returnxpathExpression - an XPath expression compiled previouslyas - the type expected to be matched by the xpathXPathExpressionException - if xpathExpression cannot be evaluatedpublic <T> T evaluateXPath(XPathExpression xpathExpression, Node context, Class<T> as) throws XPathExpressionException
Evaluate a compiled XPath expression relative to a node such as a node returned by a previous XPath expression. An XPath expression can return a Node or subinterface such as Element or Text, a NodeList, or a Boolean, Number, or String value.
T - the type to returnxpathExpression - an XPath expression compiled previouslycontext - the node for evaluating the expressionas - the type expected to be matched by the xpathXPathExpressionException - if xpathExpression cannot be evaluatedpublic void write(OutputStream out) throws IOException
OutputStreamSenderImplements a callback to write content to the provided output stream for sending to the database server.
write in interface OutputStreamSenderout - the output stream receiving the contentIOException - if io problems ariseCopyright © 2013-2017 MarkLogic Corporation.