public class ElementWrapper extends Object implements Element, Serializable
ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE
Constructor and Description |
---|
ElementWrapper(Element element) |
Modifier and Type | Method and Description |
---|---|
void |
accept(Visitor visitor)
accept is the method used in the Visitor Pattern. |
void |
add(Attribute attribute)
Adds the given
Attribute to this element. |
void |
add(CDATA cdata)
Adds the given
CDATA to this element. |
void |
add(Comment comment)
Adds the given
Comment to this branch. |
void |
add(Element element)
Adds the given
Element to this branch. |
void |
add(Entity entity)
Adds the given
Entity to this element. |
void |
add(Namespace namespace)
Adds the given
Namespace to this element. |
void |
add(Node node)
Adds the given
Node or throws IllegalAddException
if the given node is not of a valid type. |
void |
add(ProcessingInstruction processingInstruction)
Adds the given
ProcessingInstruction to this branch. |
void |
add(Text text)
Adds the given
Text to this element. |
Element |
addAttribute(QName attrName,
String text)
Adds the attribute value of the given fully qualified name.
|
Element |
addAttribute(String attrName,
String text)
Adds the attribute value of the given local name.
|
Element |
addCDATA(String text)
Adds a new
CDATA node with the given text to this element. |
Element |
addComment(String text)
Adds a new
Comment node with the given text to this
element. |
Element |
addElement(QName qName)
Adds a new
Element node with the given QName to
this branch and returns a reference to the new node. |
Element |
addElement(String name)
Adds a new
Element node with the given name to this branch
and returns a reference to the new node. |
Element |
addElement(String name,
String text)
Adds a new
Element node with the given qualified name and
namespace URI to this branch and returns a reference to the new node. |
Element |
addEntity(String name,
String text)
Adds a new
Entity node with the given name and text to
this element and returns a reference to the new node. |
List |
additionalNamespaces()
Returns any additional namespaces declarations for this element other
than namespace returned via the
Element.getNamespace() method. |
Element |
addNamespace(String prefix,
String uri)
Adds a namespace to this element for use by its child content
|
Element |
addProcessingInstruction(String target,
Map data)
Adds a processing instruction for the given target
|
Element |
addProcessingInstruction(String target,
String text)
Adds a processing instruction for the given target
|
Element |
addText(String text)
Adds a new
Text node with the given text to this element. |
void |
appendAttributes(Element element)
Appends the attributes of the given element to me.
|
void |
appendContent(Branch branch)
Appends the content of the given branch to this branch instance.
|
String |
asXML()
asXML returns the textual XML representation of this node. |
Node |
asXPathResult(Element element)
asXPathResult returns a version of this node which is
capable of being an XPath result. |
Attribute |
attribute(int i)
Returns the attribute at the specified indexGets the
|
Attribute |
attribute(QName qName)
DOCUMENT ME!
|
Attribute |
attribute(String name)
Returns the attribute with the given name
|
int |
attributeCount()
DOCUMENT ME!
|
Iterator |
attributeIterator()
DOCUMENT ME!
|
List |
attributes()
|
String |
attributeValue(QName qName)
This returns the attribute value for the attribute with the given fully
qualified name or null if there is no such attribute or the empty string
if the attribute value is empty.
|
String |
attributeValue(QName qName,
String defaultValue)
This returns the attribute value for the attribute with the given fully
qualified name or the default value if there is no such attribute value.
|
String |
attributeValue(String name)
This returns the attribute value for the attribute with the given name
and any namespace or null if there is no such attribute or the empty
string if the attribute value is empty.
|
String |
attributeValue(String name,
String defaultValue)
This returns the attribute value for the attribute with the given name
and any namespace or the default value if there is no such attribute
value.
|
void |
clearContent()
Clears the content for this branch, removing any
Node
instances this branch may contain. |
Object |
clone()
clone will return a deep clone or if this node is
read-only then clone will return the same instance. |
List |
content()
|
Element |
createCopy()
Creates a deep copy of this element The new element is detached from its
parent, and getParent() on the clone will return null.
|
Element |
createCopy(QName qName)
Creates a deep copy of this element with the given fully qualified name.
|
Element |
createCopy(String name)
Creates a deep copy of this element with the given local name The new
element is detached from its parent, and getParent() on the clone will
return null.
|
XPath |
createXPath(String xpath)
createXPath creates an XPath object for the given
xpathExpression. |
List |
declaredNamespaces()
Returns all the namespaces declared by this element.
|
Node |
detach()
Removes this node from its parent if there is one.
|
Element |
element(QName qName)
Returns the first element for the given fully qualified name.
|
Element |
element(String name)
Returns the first element for the given local name and any namespace.
|
Element |
elementByID(String id)
Returns the element of the given ID attribute value.
|
Iterator |
elementIterator()
Returns an iterator over all this elements child elements.
|
Iterator |
elementIterator(QName qName)
Returns an iterator over the elements contained in this element which
match the given fully qualified name.
|
Iterator |
elementIterator(String name)
Returns an iterator over the elements contained in this element which
match the given local name and any namespace.
|
List |
elements()
Returns the elements contained in this element.
|
List |
elements(QName qName)
Returns the elements contained in this element with the given fully
qualified name.
|
List |
elements(String name)
Returns the elements contained in this element with the given local name
and any namespace.
|
String |
elementText(QName qName) |
String |
elementText(String name) |
String |
elementTextTrim(QName qName) |
String |
elementTextTrim(String name) |
boolean |
equals(Object other) |
Object |
getData()
Accesses the data of this element which may implement data typing
bindings such as XML Schema or Java Bean bindings or will return the same
value as
Element.getText() |
Document |
getDocument()
getDocument returns the Document that this
Node is part of if this node supports the parent
relationship. |
Element |
getElement() |
String |
getName()
getName returns the name of this node. |
Namespace |
getNamespace()
Returns the
Namespace of this element if one exists
otherwise Namespace.NO_NAMESPACE is returned. |
Namespace |
getNamespaceForPrefix(String s)
Returns the
Namespace which is mapped to the given prefix
or null if it could not be found. |
Namespace |
getNamespaceForURI(String s)
Returns the
Namespace which is mapped to the given URI or
null if it could not be found. |
String |
getNamespacePrefix()
Returns the namespace prefix of this element if one exists otherwise an
empty
String is returned. |
List |
getNamespacesForURI(String s)
Returns the all namespaces which are mapped to the given URI or an empty
list if no such namespaces could be found.
|
String |
getNamespaceURI()
Returns the URI mapped to the namespace of this element if one exists
otherwise an empty
String is returned. |
short |
getNodeType()
Returns the code according to the type of node.
|
String |
getNodeTypeName()
DOCUMENT ME!
|
Element |
getParent()
getParent returns the parent Element if
this node supports the parent relationship or null if it is the root
element or does not support the parent relationship. |
String |
getPath()
Returns the XPath expression which will return a node set containing the
given node such as /a/b/@c.
|
String |
getPath(Element element)
Returns the relative XPath expression which will return a node set
containing the given node such as a/b/@c.
|
QName |
getQName()
Returns the
QName of this element which represents the
local name, the qualified name and the Namespace . |
QName |
getQName(String s)
Returns the
QName for the given qualified name, using the
namespace URI in scope for the given prefix of the qualified name or the
default namespace if the qualified name has no prefix. |
String |
getQualifiedName()
Returns the fully qualified name of this element.
|
String |
getStringValue()
Returns the XPath string-value of this node.
|
String |
getText()
Returns the text value of this element without recursing through child
elements.
|
String |
getTextTrim()
DOCUMENT ME!
|
String |
getUniquePath()
Returns the XPath expression which will return a nodeset of one node
which is the current node.
|
String |
getUniquePath(Element element)
Returns the relative unique XPath expression from the given context which
will return a nodeset of one node which is the current node.
|
Node |
getXPathResult(int i)
Returns a node at the given index suitable for an XPath result set.
|
boolean |
hasContent()
hasContent returns true if this node is a Branch (either
an Element or a Document) and it contains at least one content node such
as a child Element or Text node. |
int |
hashCode() |
boolean |
hasMixedContent()
Returns true if this
Element has mixed content. |
int |
indexOf(Node node)
Returns the index of the given node if it is a child node of this branch
or -1 if the given node is not a child node.
|
boolean |
isReadOnly()
isReadOnly returns true if this node is read only and
cannot be modified. |
boolean |
isRootElement()
DOCUMENT ME!
|
boolean |
isTextOnly()
Returns true if this
Element has text only content. |
boolean |
matches(String xpath)
matches returns true if evaluating the given XPath
expression on this node returns a non-empty node set containing this
node. |
Node |
node(int i)
Returns the
Node at the specified index position. |
int |
nodeCount()
Returns the number of
Node instances that this branch
contains. |
Iterator |
nodeIterator()
Returns an iterator through the content nodes of this branch
|
void |
normalize()
Puts all
Text nodes in the full depth of the sub-tree
underneath this Node , including attribute nodes, into a
"normal" form where only structure (e.g., elements, comments, processing
instructions, CDATA sections, and entity references) separates
Text nodes, i.e., there are neither adjacent
Text nodes nor empty Text nodes. |
Number |
numberValueOf(String xpath)
numberValueOf evaluates an XPath expression and returns
the numeric value of the XPath expression if the XPath expression results
in a number, or null if the result is not a number. |
ProcessingInstruction |
processingInstruction(String name)
DOCUMENT ME!
|
List |
processingInstructions()
Returns a list of all the processing instructions in this branch.
|
List |
processingInstructions(String name)
Returns a list of the processing instructions for the given target.
|
boolean |
remove(Attribute attribute)
Removes the given
Attribute from this element. |
boolean |
remove(CDATA cdata)
Removes the given
CDATA if the node is an immediate child
of this element. |
boolean |
remove(Comment comment)
Removes the given
Comment if the node is an immediate
child of this branch. |
boolean |
remove(Element element)
Removes the given
Element if the node is an immediate
child of this branch. |
boolean |
remove(Entity entity)
Removes the given
Entity if the node is an immediate child
of this element. |
boolean |
remove(Namespace namespace)
Removes the given
Namespace if the node is an immediate
child of this element. |
boolean |
remove(Node node)
Removes the given
Node if the node is an immediate child
of this branch. |
boolean |
remove(ProcessingInstruction processingInstruction)
Removes the given
ProcessingInstruction if the node is an
immediate child of this branch. |
boolean |
remove(Text text)
Removes the given
Text if the node is an immediate child
of this element. |
boolean |
removeProcessingInstruction(String name)
Removes the processing instruction for the given target if it exists
|
List |
selectNodes(String xpath)
selectNodes evaluates an XPath expression and returns the
result as a List of Node instances or
String instances depending on the XPath expression. |
List |
selectNodes(String xpath,
String comparison)
selectNodes evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List of Node instances. |
List |
selectNodes(String xpath,
String comparison,
boolean removeDups)
selectNodes evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List of Node instances. |
Object |
selectObject(String xpath)
selectObject evaluates an XPath expression and returns the
result as an Object . |
Node |
selectSingleNode(String xpath)
selectSingleNode evaluates an XPath expression and returns
the result as a single Node instance. |
void |
setAttributes(List list)
Sets the attributes that this element contains
|
void |
setAttributeValue(QName qName,
String value)
Deprecated.
|
void |
setAttributeValue(String name,
String value)
Deprecated.
|
void |
setContent(List list)
Sets the contents of this branch as a
List of
Node instances. |
void |
setData(Object data)
Sets the data value of this element if this element supports data binding
or calls
Node.setText(java.lang.String) if it doesn't |
void |
setDocument(Document document)
setDocument sets the document of this node if the parent
relationship is supported or does nothing if the parent relationship is
not supported. |
void |
setName(String name)
Sets the text data of this node or this method will throw an
UnsupportedOperationException if it is read-only. |
void |
setParent(Element parent)
setParent sets the parent relationship of this node if the
parent relationship is supported or does nothing if the parent
relationship is not supported. |
void |
setProcessingInstructions(List list)
Sets all the processing instructions for this branch
|
void |
setQName(QName qName)
Sets the
QName of this element which represents the local
name, the qualified name and the Namespace . |
void |
setText(String text)
Sets the text data of this node or this method will throw an
UnsupportedOperationException if it is read-only. |
boolean |
supportsParent()
supportsParent returns true if this node supports the
parent relationship. |
String |
toString() |
String |
valueOf(String xpath)
valueOf evaluates an XPath expression and returns the
textual representation of the results the XPath string-value of this
node. |
void |
write(Writer writer)
write writes this node as the default XML notation for
this node. |
public ElementWrapper(Element element)
public Element getElement()
public QName getQName()
Element
Returns the QName
of this element which represents the
local name, the qualified name and the Namespace
.
public QName getQName(String s)
Element
Returns the QName
for the given qualified name, using the
namespace URI in scope for the given prefix of the qualified name or the
default namespace if the qualified name has no prefix.
public void setQName(QName qName)
Element
Sets the QName
of this element which represents the local
name, the qualified name and the Namespace
.
public Namespace getNamespace()
Element
Returns the Namespace
of this element if one exists
otherwise Namespace.NO_NAMESPACE
is returned.
getNamespace
in interface Element
Namespace
associated with this elementpublic Namespace getNamespaceForPrefix(String s)
Element
Returns the Namespace
which is mapped to the given prefix
or null if it could not be found.
getNamespaceForPrefix
in interface Element
s
- DOCUMENT ME!Namespace
associated with the given prefixpublic Namespace getNamespaceForURI(String s)
Element
Returns the Namespace
which is mapped to the given URI or
null if it could not be found. If there is more than one
Namespace
mapped to the URI, which of them will be
returned is undetermined.
getNamespaceForURI
in interface Element
s
- DOCUMENT ME!Namespace
associated with the given URIpublic List getNamespacesForURI(String s)
Element
Returns the all namespaces which are mapped to the given URI or an empty list if no such namespaces could be found.
getNamespacesForURI
in interface Element
s
- DOCUMENT ME!public String getNamespacePrefix()
Element
Returns the namespace prefix of this element if one exists otherwise an
empty String
is returned.
getNamespacePrefix
in interface Element
Namespace
of this element or an
empty String
public String getNamespaceURI()
Element
Returns the URI mapped to the namespace of this element if one exists
otherwise an empty String
is returned.
getNamespaceURI
in interface Element
Namespace
of this element or an
empty String
public String getQualifiedName()
Element
Returns the fully qualified name of this element. This will be the same
as the value returned from Node.getName()
if this element has no
namespace attached to this element or an expression of the form
getNamespacePrefix() + ":" + getName()will be returned.
getQualifiedName
in interface Element
public List additionalNamespaces()
Element
Returns any additional namespaces declarations for this element other
than namespace returned via the Element.getNamespace()
method. If no
additional namespace declarations are present for this element then an
empty list will be returned. The list is backed by the element such that
changes to the list will be reflected in the element though the reverse
is not the case.
additionalNamespaces
in interface Element
public List declaredNamespaces()
Element
Returns all the namespaces declared by this element. If no namespaces are declared for this element then an empty list will be returned. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
declaredNamespaces
in interface Element
public Element addAttribute(String attrName, String text)
Element
Adds the attribute value of the given local name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.
addAttribute
in interface Element
attrName
- is the name of the attribute whose value is to be added or
updatedtext
- is the attribute's valueElement
instance.public Element addAttribute(QName attrName, String text)
Element
Adds the attribute value of the given fully qualified name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.
addAttribute
in interface Element
attrName
- is the fully qualified name of the attribute whose value is to
be added or updatedtext
- is the attribute's valueElement
instance.public Element addComment(String text)
Element
Comment
node with the given text to this
element.addComment
in interface Element
text
- is the text for the Comment
node.Element
instance.public Element addCDATA(String text)
Element
CDATA
node with the given text to this element.public Element addEntity(String name, String text)
Element
Entity
node with the given name and text to
this element and returns a reference to the new node.public Element addNamespace(String prefix, String uri)
Element
addNamespace
in interface Element
prefix
- is the prefix to use, which should not be null or blankuri
- is the namespace URIElement
instance.public Element addProcessingInstruction(String target, String text)
Element
addProcessingInstruction
in interface Element
target
- is the target of the processing instructiontext
- is the textual data (key/value pairs) of the processing
instructionElement
instance.public Element addProcessingInstruction(String target, Map data)
Element
addProcessingInstruction
in interface Element
target
- is the target of the processing instructiondata
- is a Map of the key / value pairs of the processing
instructionElement
instance.public Element addText(String text)
Element
Text
node with the given text to this element.public void add(Attribute attribute)
Element
Attribute
to this element. If the given
node already has a parent defined then an
IllegalAddException
will be thrown. Attributes with null
values are silently ignored.
If the value of the attribute is null then this method call will remove any attributes with the QName of this attribute.
public void add(CDATA cdata)
Element
CDATA
to this element. If the given node
already has a parent defined then an IllegalAddException
will be thrown.public void add(Entity entity)
Element
Entity
to this element. If the given node
already has a parent defined then an IllegalAddException
will be thrown.public void add(Text text)
Element
Text
to this element. If the given node
already has a parent defined then an IllegalAddException
will be thrown.public void add(Namespace namespace)
Element
Namespace
to this element. If the given
node already has a parent defined then an
IllegalAddException
will be thrown.public boolean remove(Attribute attribute)
Element
Attribute
from this element.public boolean remove(CDATA cdata)
Element
CDATA
if the node is an immediate child
of this element. If the given node is not an immediate child of this
element then the Node.detach()
method should be used instead.public boolean remove(Entity entity)
Element
Entity
if the node is an immediate child
of this element. If the given node is not an immediate child of this
element then the Node.detach()
method should be used instead.public boolean remove(Namespace namespace)
Element
Namespace
if the node is an immediate
child of this element. If the given node is not an immediate child of
this element then the Node.detach()
method should be used
instead.public boolean remove(Text text)
Element
Text
if the node is an immediate child
of this element. If the given node is not an immediate child of this
element then the Node.detach()
method should be used instead.public boolean supportsParent()
Node
supportsParent
returns true if this node supports the
parent relationship.
Some XML tree implementations are singly linked and only support downward navigation through children relationships. The default case is that both parent and children relationships are supported though for memory and performance reasons the parent relationship may not be supported.
supportsParent
in interface Node
public Element getParent()
Node
getParent
returns the parent Element
if
this node supports the parent relationship or null if it is the root
element or does not support the parent relationship.
This method is an optional feature and may not be supported for all
Node
implementations.
public void setParent(Element parent)
Node
setParent
sets the parent relationship of this node if the
parent relationship is supported or does nothing if the parent
relationship is not supported.
This method should only be called from inside an Element
implementation method and is not intended for general use.
public Document getDocument()
Node
getDocument
returns the Document
that this
Node
is part of if this node supports the parent
relationship.
This method is an optional feature and may not be supported for all
Node
implementations.
getDocument
in interface Node
Document
public void setDocument(Document document)
Node
setDocument
sets the document of this node if the parent
relationship is supported or does nothing if the parent relationship is
not supported.
This method should only be called from inside a Document
implementation method and is not intended for general use.
setDocument
in interface Node
document
- is the new document of this node.public boolean isReadOnly()
Node
isReadOnly
returns true if this node is read only and
cannot be modified. Any attempt to modify a read-only Node
will result in an UnsupportedOperationException
being
thrown.
isReadOnly
in interface Node
Node
is read only and cannot be
modified otherwise false.public boolean hasContent()
Node
hasContent
returns true if this node is a Branch (either
an Element or a Document) and it contains at least one content node such
as a child Element or Text node.
hasContent
in interface Node
Node
is a Branch with a nodeCount()
of one or more.public String getName()
Node
getName
returns the name of this node. This is the XML
local name of the element, attribute, entity or processing instruction.
For CDATA and Text nodes this method will return null.
public void setName(String name)
Node
Sets the text data of this node or this method will throw an
UnsupportedOperationException
if it is read-only.
public void setText(String text)
Node
Sets the text data of this node or this method will throw an
UnsupportedOperationException
if it is read-only.
public String getTextTrim()
Element
getTextTrim
in interface Element
public String getStringValue()
Element
Text
,CDATA
,Entity
and Element
nodes all appended together.getStringValue
in interface Element
getStringValue
in interface Node
public String getPath()
Node
Returns the XPath expression which will return a node set containing the given node such as /a/b/@c. No indexing will be used to restrict the path if multiple elements with the same name occur on the path.
public String getPath(Element element)
Node
getPath
in interface Node
element
- is the parent context from which the relative path should
start. If the context is null or the context is not an
ancestor of this node then the path will be absolute and start
from the document and so begin with the '/' character.public String getUniquePath()
Node
Returns the XPath expression which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.
getUniquePath
in interface Node
public String getUniquePath(Element element)
Node
Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.
getUniquePath
in interface Node
element
- is the parent context from which the path should start. If the
context is null or the context is not an ancestor of this node
then the path will start from the document and so begin with
the '/' character.public String asXML()
Node
asXML
returns the textual XML representation of this node.
public void write(Writer writer) throws IOException
Node
write
writes this node as the default XML notation for
this node. If you wish to control the XML output (such as for pretty
printing, changing the indentation policy etc.) then please use XMLWriter
or its derivations.
write
in interface Node
writer
- is the Writer
to output the XML toIOException
- DOCUMENT ME!public short getNodeType()
Node
getNodeType
in interface Node
public String getNodeTypeName()
Node
getNodeTypeName
in interface Node
public Node detach()
Node
Removes this node from its parent if there is one. If this node is the root element of a document then it is removed from the document as well.
This method is useful if you want to remove a node from its source document and add it to another document. For example
Node node = ...; Element someOtherElement = ...;
someOtherElement.add( node.detach() );
public List selectNodes(String xpath)
Node
selectNodes
evaluates an XPath expression and returns the
result as a List
of Node
instances or
String
instances depending on the XPath expression.
selectNodes
in interface Node
xpath
- is the XPath expression to be evaluatedNode
or String
instances depending on the XPath expressionpublic List selectNodes(String xpath, String comparison)
Node
selectNodes
evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List
of Node
instances.
selectNodes
in interface Node
xpath
- is the XPath expression to be evaluatedcomparison
- is the XPath expression used to compare the results by for
sortingNode
instances sorted by the
comparisonXPathExpressionpublic List selectNodes(String xpath, String comparison, boolean removeDups)
Node
selectNodes
evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List
of Node
instances.
selectNodes
in interface Node
xpath
- is the XPath expression to be evaluatedcomparison
- is the XPath expression used to compare the results by for
sortingremoveDups
- if this parameter is true then duplicate values (using the
comparisonXPathExpression) are removed from the result List.Node
instances sorted by the
comparisonXPathExpressionpublic Node selectSingleNode(String xpath)
Node
selectSingleNode
evaluates an XPath expression and returns
the result as a single Node
instance.
selectSingleNode
in interface Node
xpath
- is the XPath expression to be evaluatedNode
matching the XPath expressionpublic String valueOf(String xpath)
Node
valueOf
evaluates an XPath expression and returns the
textual representation of the results the XPath string-value of this
node. The string-value for a given node type is defined in the XPath specification .
public Number numberValueOf(String xpath)
Node
numberValueOf
evaluates an XPath expression and returns
the numeric value of the XPath expression if the XPath expression results
in a number, or null if the result is not a number.
numberValueOf
in interface Node
xpath
- is the XPath expression to be evaluatedpublic boolean matches(String xpath)
Node
matches
returns true if evaluating the given XPath
expression on this node returns a non-empty node set containing this
node.
This method does not behave like the <xsl:if> element - if you want that behaviour, to evaluate if an XPath expression matches something, then you can use the following code to be equivalent...
if ( node.selectSingleNode( "/some/path" ) != nulll )
public XPath createXPath(String xpath) throws InvalidXPathException
Node
createXPath
creates an XPath object for the given
xpathExpression. The XPath object allows the variable context to be
specified.
createXPath
in interface Node
xpath
- is the XPath expression to be evaluatedInvalidXPathException
- if the XPath expression is invalidpublic Node asXPathResult(Element element)
Node
asXPathResult
returns a version of this node which is
capable of being an XPath result. The result of an XPath expression
should always support the parent relationship, whether the original XML
tree was singly or doubly linked. If the node does not support the parent
relationship then a new node will be created which is linked to its
parent and returned.
asXPathResult
in interface Node
element
- DOCUMENT ME!Node
which supports the parent relationshippublic void accept(Visitor visitor)
Node
accept
is the method used in the Visitor Pattern.
public Object clone()
Node
clone
will return a deep clone or if this node is
read-only then clone will return the same instance.
public Object getData()
Element
Element.getText()
public void setData(Object data)
Element
Node.setText(java.lang.String)
if it doesn'tpublic List attributes()
Element
Returns the Attribute
instances this element contains as a backed
List
so that the attributes may be modified directly using the
List
interface. The List
is backed by the
Element
so that changes to the list are reflected in the
element and vice versa.
attributes
in interface Element
List
public void setAttributes(List list)
Element
setAttributes
in interface Element
list
- DOCUMENT ME!public int attributeCount()
Element
attributeCount
in interface Element
public Iterator attributeIterator()
Element
attributeIterator
in interface Element
public Attribute attribute(int i)
Element
public Attribute attribute(String name)
Element
public Attribute attribute(QName qName)
Element
public String attributeValue(String name)
Element
This returns the attribute value for the attribute with the given name and any namespace or null if there is no such attribute or the empty string if the attribute value is empty.
attributeValue
in interface Element
name
- is the name of the attribute value to be returndpublic String attributeValue(String name, String defaultValue)
Element
This returns the attribute value for the attribute with the given name and any namespace or the default value if there is no such attribute value.
attributeValue
in interface Element
name
- is the name of the attribute value to be returnddefaultValue
- is the default value to be returned if the attribute has no
value defined.public String attributeValue(QName qName)
Element
This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.
attributeValue
in interface Element
qName
- is the fully qualified namepublic String attributeValue(QName qName, String defaultValue)
Element
This returns the attribute value for the attribute with the given fully qualified name or the default value if there is no such attribute value.
attributeValue
in interface Element
qName
- is the fully qualified namedefaultValue
- is the default value to be returned if the attribute has no
value defined.public void setAttributeValue(String name, String value)
Element
Sets the attribute value of the given local name.
setAttributeValue
in interface Element
name
- is the name of the attribute whose value is to be added or
updatedvalue
- is the attribute's valuepublic void setAttributeValue(QName qName, String value)
Element
Sets the attribute value of the given fully qualified name.
setAttributeValue
in interface Element
qName
- is the fully qualified name of the attribute whose value is to
be added or updatedvalue
- is the attribute's valuepublic Element element(String name)
Element
public Element element(QName qName)
Element
public List elements()
Element
Returns the elements contained in this element. If this element does not contain any elements then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
public List elements(String name)
Element
Returns the elements contained in this element with the given local name and any namespace. If no elements are found then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
public List elements(QName qName)
Element
Returns the elements contained in this element with the given fully qualified name. If no elements are found then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
public Iterator elementIterator()
Element
elementIterator
in interface Element
public Iterator elementIterator(String name)
Element
elementIterator
in interface Element
name
- DOCUMENT ME!public Iterator elementIterator(QName qName)
Element
elementIterator
in interface Element
qName
- is the fully qualified name to search forpublic boolean isRootElement()
Element
isRootElement
in interface Element
public boolean hasMixedContent()
Element
Returns true if this Element
has mixed content. Mixed
content means that an element contains both textual data and child
elements.
hasMixedContent
in interface Element
public boolean isTextOnly()
Element
Returns true if this Element
has text only content.
isTextOnly
in interface Element
public void appendAttributes(Element element)
Element
Collection.addAll(java.util.Collection)
method.appendAttributes
in interface Element
element
- is the element whose attributes will be added to me.public Element createCopy()
Element
Creates a deep copy of this element The new element is detached from its parent, and getParent() on the clone will return null.
createCopy
in interface Element
public Element createCopy(String name)
Element
Creates a deep copy of this element with the given local name The new element is detached from its parent, and getParent() on the clone will return null.
createCopy
in interface Element
name
- DOCUMENT ME!public Element createCopy(QName qName)
Element
Creates a deep copy of this element with the given fully qualified name. The new element is detached from its parent, and getParent() on the clone will return null.
createCopy
in interface Element
qName
- DOCUMENT ME!public String elementText(String name)
elementText
in interface Element
public String elementText(QName qName)
elementText
in interface Element
public String elementTextTrim(String name)
elementTextTrim
in interface Element
public String elementTextTrim(QName qName)
elementTextTrim
in interface Element
public Node getXPathResult(int i)
Element
getXPathResult
in interface Element
i
- DOCUMENT ME!public Node node(int i)
Branch
Node
at the specified index position.public int indexOf(Node node)
Branch
public int nodeCount()
Branch
Node
instances that this branch
contains.public Element elementByID(String id)
Branch
elementByID
in interface Branch
id
- DOCUMENT ME!public Iterator nodeIterator()
Branch
nodeIterator
in interface Branch
public void setContent(List list)
Branch
List
of
Node
instances.setContent
in interface Branch
list
- is the list of nodes to use as the content for this branch.public void appendContent(Branch branch)
Branch
Collection.addAll(java.util.Collection)
method.appendContent
in interface Branch
branch
- is the branch whose content will be added to me.public void clearContent()
Branch
Node
instances this branch may contain.clearContent
in interface Branch
public List processingInstructions()
Branch
Returns a list of all the processing instructions in this branch. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.
processingInstructions
in interface Branch
public List processingInstructions(String name)
Branch
Returns a list of the processing instructions for the given target. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.
processingInstructions
in interface Branch
name
- DOCUMENT ME!public ProcessingInstruction processingInstruction(String name)
Branch
processingInstruction
in interface Branch
name
- DOCUMENT ME!public void setProcessingInstructions(List list)
Branch
setProcessingInstructions
in interface Branch
list
- DOCUMENT ME!public Element addElement(String name)
Branch
Element
node with the given name to this branch
and returns a reference to the new node.addElement
in interface Branch
name
- is the name for the Element
node.Element
node.public Element addElement(QName qName)
Branch
Element
node with the given QName
to
this branch and returns a reference to the new node.addElement
in interface Branch
qName
- is the qualified name for the Element
node.Element
node.public Element addElement(String name, String text)
Branch
Element
node with the given qualified name and
namespace URI to this branch and returns a reference to the new node.addElement
in interface Branch
name
- is the fully qualified name of the Elementtext
- is the URI of the namespace to useElement
node.public boolean removeProcessingInstruction(String name)
Branch
removeProcessingInstruction
in interface Branch
name
- DOCUMENT ME!public void add(Node node)
Branch
Node
or throws IllegalAddException
if the given node is not of a valid type. This is a polymorphic method
which will call the typesafe method for the node type such as
add(Element) or add(Comment).public void add(Comment comment)
Branch
Comment
to this branch. If the given node
already has a parent defined then an IllegalAddException
will be thrown.public void add(Element element)
Branch
Element
to this branch. If the given node
already has a parent defined then an IllegalAddException
will be thrown.public void add(ProcessingInstruction processingInstruction)
Branch
ProcessingInstruction
to this branch. If
the given node already has a parent defined then an
IllegalAddException
will be thrown.public boolean remove(Node node)
Branch
Node
if the node is an immediate child
of this branch. If the given node is not an immediate child of this
branch then the Node.detach()
method should be used instead. This
is a polymorphic method which will call the typesafe method for the node
type such as remove(Element) or remove(Comment).public boolean remove(Comment comment)
Branch
Comment
if the node is an immediate
child of this branch. If the given node is not an immediate child of this
branch then the Node.detach()
method should be used instead.public boolean remove(Element element)
Branch
Element
if the node is an immediate
child of this branch. If the given node is not an immediate child of this
branch then the Node.detach()
method should be used instead.public boolean remove(ProcessingInstruction processingInstruction)
Branch
ProcessingInstruction
if the node is an
immediate child of this branch. If the given node is not an immediate
child of this branch then the Node.detach()
method should be used
instead.public void normalize()
Branch
Text
nodes in the full depth of the sub-tree
underneath this Node
, including attribute nodes, into a
"normal" form where only structure (e.g., elements, comments, processing
instructions, CDATA sections, and entity references) separates
Text
nodes, i.e., there are neither adjacent
Text
nodes nor empty Text
nodes. This can
be used to ensure that the DOM view of a document is the same as if it
were saved and re-loaded, and is useful when operations (such as XPointer
lookups) that depend on a particular document tree structure are to be
used.In cases where the document contains CDATASections
,
the normalize operation alone may not be sufficient, since XPointers do
not differentiate between Text
nodes and
CDATASection
nodes.Copyright © 2012 JBoss by Red Hat. All Rights Reserved.