"Document" and "DocumentTraversal" implementation.
Note that when this checks names for legality, it uses an
approximation of the XML rules, not the real ones. Specifically,
it uses Unicode rules, with sufficient tweaks to pass a majority
of basic XML conformance tests. (The huge XML character tables are
hairy to implement.)
appendChild
public Node appendChild(Node newChild)
DOM L1
Appends the specified node to this node's list of children,
enforcing the constraints that there be only one root element
and one document type child.
- appendChild in interface Node
- appendChild in interface DomNode
createAttribute
public Attr createAttribute(String name)
DOM L1
Returns a newly created attribute with the specified name.
- createAttribute in interface Document
createAttributeNS
public Attr createAttributeNS(String namespaceURI,
String name)
DOM L2
Returns a newly created attribute with the specified name
and namespace information.
- createAttributeNS in interface Document
createCDATASection
public CDATASection createCDATASection(char[] buf,
int off,
int len)
Returns a newly created CDATA section node with the specified value.
createComment
public Comment createComment(String value)
DOM L1
Returns a newly created comment node with the specified value.
- createComment in interface Document
createElement
public Element createElement(String name)
DOM L1
Returns a newly created element with the specified name.
- createElement in interface Document
createElementNS
public Element createElementNS(String namespaceURI,
String name)
DOM L2
Returns a newly created element with the specified name
and namespace information.
- createElementNS in interface Document
createExpression
public XPathExpression createExpression(String expression,
XPathNSResolver resolver)
throws XPathException,
DOMException
Creates a parsed XPath expression with resolved namespaces. This is
useful when an expression will be reused in an application since it
makes it possible to compile the expression string into a more
efficient internal form and preresolve all namespace prefixes which
occur within the expression.
- createExpression in interface XPathEvaluator
expression
- The XPath expression string to be parsed.resolver
- The resolver
permits translation of all
prefixes, including the xml
namespace prefix, within
the XPath expression into appropriate namespace URIs. If this is
specified as null
, any namespace prefix within the
expression will result in DOMException
being thrown
with the code NAMESPACE_ERR
.
- The compiled form of the XPath expression.
XPathException
- INVALID_EXPRESSION_ERR: Raised if the expression is not legal
according to the rules of the XPathEvaluator
.DOMException
- NAMESPACE_ERR: Raised if the expression contains namespace prefixes
which cannot be resolved by the specified
XPathNSResolver
.
createNSResolver
public XPathNSResolver createNSResolver(Node nodeResolver)
Adapts any DOM node to resolve namespaces so that an XPath expression
can be easily evaluated relative to the context of the node where it
appeared within the document. This adapter works like the DOM Level 3
method lookupNamespaceURI
on nodes in resolving the
namespaceURI from a given prefix using the current information
available in the node's hierarchy at the time lookupNamespaceURI is
called. also correctly resolving the implicit xml prefix.
- createNSResolver in interface XPathEvaluator
nodeResolver
- The node to be used as a context for namespace
resolution.
XPathNSResolver
which resolves namespaces with
respect to the definitions in scope for a specified node.
createTextNode
public Text createTextNode(String value)
DOM L1
Returns a newly created text node with the specified value.
- createTextNode in interface Document
createTextNode
public Text createTextNode(char[] buf,
int off,
int len)
Returns a newly created text node with the specified value.
evaluate
public Object evaluate(String expression,
Node contextNode,
XPathNSResolver resolver,
short type,
Object result)
throws XPathException,
DOMException
Evaluates an XPath expression string and returns a result of the
specified type if possible.
- evaluate in interface XPathEvaluator
expression
- The XPath expression string to be parsed and
evaluated.contextNode
- The context
is context node for the
evaluation of this XPath expression. If the XPathEvaluator was
obtained by casting the Document
then this must be
owned by the same document and must be a Document
,
Element
, Attribute
, Text
,
CDATASection
, Comment
,
ProcessingInstruction
, or XPathNamespace
node. If the context node is a Text
or a
CDATASection
, then the context is interpreted as the
whole logical text node as seen by XPath, unless the node is empty
in which case it may not serve as the XPath context.resolver
- The resolver
permits translation of all
prefixes, including the xml
namespace prefix, within
the XPath expression into appropriate namespace URIs. If this is
specified as null
, any namespace prefix within the
expression will result in DOMException
being thrown
with the code NAMESPACE_ERR
.type
- If a specific type
is specified, then the
result will be returned as the corresponding type.For XPath 1.0
results, this must be one of the codes of the
XPathResult
interface.result
- The result
specifies a specific result
object which may be reused and returned by this method. If this is
specified as null
or the implementation does not reuse
the specified result, a new result object will be constructed and
returned.For XPath 1.0 results, this object will be of type
XPathResult
.
- The result of the evaluation of the XPath expression.For XPath
1.0 results, this object will be of type
XPathResult
.
XPathException
- INVALID_EXPRESSION_ERR: Raised if the expression is not legal
according to the rules of the XPathEvaluator
i
TYPE_ERR: Raised if the result cannot be converted to return the
specified type.DOMException
- NAMESPACE_ERR: Raised if the expression contains namespace prefixes
which cannot be resolved by the specified
XPathNSResolver
.
WRONG_DOCUMENT_ERR: The Node is from a document that is not
supported by this XPathEvaluator
.
NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath
context node or the request type is not permitted by this
XPathEvaluator
.
getBaseURI
public String getBaseURI()
The absolute base URI of this node or
null
if the
implementation wasn't able to obtain an absolute URI. This value is
computed as described in . However, when the
Document
supports the feature "HTML" [
DOM Level 2 HTML]
, the base URI is computed using first the value of the href
attribute of the HTML BASE element if any, and the value of the
documentURI
attribute from the
Document
interface otherwise.
- getBaseURI in interface Node
- getBaseURI in interface DomNode
- DOM Level 3
getElementById
public Element getElementById(String id)
DOM L1 (relocated in DOM L2)
Returns the element with the specified "ID" attribute, or null.
Returns null unless
Consumer
was used to populate internal
DTD declaration information, using package-private APIs. If that
internal DTD information is available, the document may be searched for
the element with that ID.
- getElementById in interface Document
getNodeName
public final String getNodeName()
DOM L1
Returns the constant "#document".
- getNodeName in interface Node
- getNodeName in interface DomNode
importNode
public Node importNode(Node src,
boolean deep)
DOM L2
Makes a copy of the specified node, with all nodes "owned" by
this document and with children optionally copied. This type
of standard utility has become, well, a standard utility.
Note that EntityReference nodes created through this method (either
directly, or recursively) never have children, and that there is no
portable way to associate them with such children.
Note also that there is no requirement that the specified node
be associated with a different document. This differs from the
cloneNode operation in that the node itself is not given
an opportunity to participate, so that any information managed
by node subclasses will be lost.
- importNode in interface Document
insertBefore
public Node insertBefore(Node newChild,
Node refChild)
DOM L1
Inserts the specified node in this node's list of children,
enforcing the constraints that there be only one root element
and one document type child.
- insertBefore in interface Node
- insertBefore in interface DomNode
isDefaultNamespace
public boolean isDefaultNamespace(String namespaceURI)
This method checks if the specified namespaceURI
is the
default namespace or not.
- isDefaultNamespace in interface Node
- isDefaultNamespace in interface DomNode
namespaceURI
- The namespace URI to look for.
- Returns
true
if the specified
namespaceURI
is the default namespace,
false
otherwise.
- DOM Level 3
lookupNamespaceURI
public String lookupNamespaceURI(String prefix)
Look up the namespace URI associated to the given prefix, starting from
this node.
See for details on the algorithm used by this method.
- lookupNamespaceURI in interface Node
- lookupNamespaceURI in interface DomNode
prefix
- The prefix to look for. If this parameter is
null
, the method will return the default namespace URI
if any.
- Returns the associated namespace URI or
null
if
none is found.
- DOM Level 3
lookupPrefix
public String lookupPrefix(String namespaceURI)
Look up the prefix associated to the given namespace URI, starting from
this node. The default namespace declarations are ignored by this
method.
See for details on the algorithm used by this method.
- lookupPrefix in interface Node
- lookupPrefix in interface DomNode
namespaceURI
- The namespace URI to look for.
- Returns an associated namespace prefix if found or
null
if none is found. If more than one prefix are
associated to the namespace prefix, the returned namespace prefix
is implementation dependent.
- DOM Level 3
replaceChild
public Node replaceChild(Node newChild,
Node refChild)
DOM L1
Replaces the specified node in this node's list of children,
enforcing the constraints that there be only one root element
and one document type child.
- replaceChild in interface Node
- replaceChild in interface DomNode
setBuilding
public void setBuilding(boolean flag)
Sets the building
flag.
Mutation events in the document are not reported.
setCheckWellformedness
public void setCheckWellformedness(boolean flag)
Sets whether to check for document well-formedness.
If true, an exception will be raised if a second doctype or root
element node is added to the document.
setInputEncoding
public void setInputEncoding(String inputEncoding)
setXmlEncoding
public void setXmlEncoding(String encoding)
verifyXmlName
public static void verifyXmlName(String name)
This method is deprecated and may be removed in future
versions of GNU JAXP
Throws a DOM exception if the specified name is not a legal XML 1.0
Name.