This class represents an XML element. Each element has the following properties:
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private Attribute[] | |
| private String | |
| pack-priv Namespaces | |
| private int | |
| private String | |
| private String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| private | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private void | |
| private void | |
| public void | addAttribute(Attribute
the attribute to add attribute)Adds an attribute to this element, replacing any existing attribute with the same local name and namespace URI. |
| public void | addNamespaceDeclaration(String
the prefix to declare prefix, String the absolute URI reference to map the prefix to uri)Declares a namespace prefix. |
| private void | |
| public void | appendChild(String
String to add to this node text)Converts a string to a text node and appends that node to the children of this node. |
| pack-priv Iterator | |
| pack-priv static Element | |
| private static void | |
| private void | |
| public Element | Returns: a deep copy of this element with no parentImplements abstract nu. Creates a deep copy of this element with no parent, that can be added to this document or a different one. |
| private Attribute[] | |
| private static void | |
| private static Element | |
| private static String | |
| pack-priv void | |
| public final Attribute | Returns: the attribute of this element with the specified namethe name of the attribute name)Returns the attribute with the specified name in no namespace, or null if this element does not have an attribute with that name in no namespace. |
| public final Attribute | Returns: the attribute of this element with the specified name and namespacethe local name of the attribute localName, String the namespace of the attribute namespaceURI)Returns the attribute with the specified name and namespace URI, or null if this element does not have an attribute with that name in that namespace. |
| public final Attribute | Returns: the indexth attribute of this elementthe attribute to return index)Selects an attribute by index. |
| public final int | Returns: the number of attributes in the container
Returns the number of attributes of this |
| public final String | Returns: the value of the attribute of this element with the specified namethe name of the attribute name)Returns the value of the attribute with the specified name in no namespace, or null if this element does not have an attribute with that name. |
| public final String | Returns: the value of the attribute of this element with the specified name and namespacethe name of the attribute localName, String the namespace of the attribute namespaceURI)Returns the value of the attribute with the specified name and namespace URI, or null if this element does not have such an attribute. |
| public String | Returns: the base URI of this elementOverrides nu. Returns the absolute base URI against which relative URIs in this element should be resolved. |
| public final Elements | Returns: a comatose list containing the child elements of this element with the specified namethe name of the elements included in the list name)Returns a list of the child elements of this element with the specified name in no namespace. |
| public final Elements | Returns: a comatose list containing the child elements of this element with the specified name in the specified namespacethe name of the elements included in the list localName, String the namespace URI of the elements included
in the list namespaceURI)Returns a list of the immediate child elements of this element with the specified local name and namespace URI. |
| public final Elements | Returns: a comatose list containing all child elements of this elementReturns a list of all the child elements of this element in document order. |
| private String | |
| public final Element | Returns: the first child element with the specified local name in no namespace or null if there is no such elementthe name of the element to return name)Returns the first child element with the specified name in no namespace. |
| public final Element | Returns: the first child with the specified local name in the specified namespace, or null if there is no such elementthe local name of the element to return localName, String the namespace URI of the element to return namespaceURI)Returns the first child element with the specified local name and namespace URI. |
| public final String | Returns: the local name of this elementReturns the local name of this element, not including the namespace prefix or colon. |
| pack-priv final String | |
| public final int | Returns: the number of namespaces declared by this elementReturns the number of namespace declarations on this element. |
| public final String | Returns: the prefix of this elementReturns the prefix of this element, or the empty string if this element does not have a prefix. |
| public final String | Returns: the prefixthe prefix to return index)Returns the indexth namespace prefix declared on this element. |
| private Set | |
| pack-priv Map | |
| public final String | Returns: the namespace URI of this elementReturns the namespace URI of this element, or the empty string if this element is not in a namespace. |
| public final String | Returns: the namespace URI mapped toprefixthe namespace prefix whose URI is desired prefix)Returns the namespace URI mapped to the specified prefix within this element. |
| public final String | Returns: the qualified name of this elementReturns the complete name of this element, including the namespace prefix if this element has one. |
| public final String | Returns: XPath string value of this elementImplements abstract nu. Returns the value of the element as defined by XPath 1.0. |
| private static int[] | |
| public void | insertChild(String
the string to convert to a text node and insert text, int where to insert the child position)Converts a string to a text node and inserts that node at the specified position. |
| pack-priv void | insertionAllowed(Node
the node to insert child, int where to insert the child position)Implements abstract nu. Inserts a child node at the specified position. |
| pack-priv boolean | |
| private boolean | |
| private boolean | |
| public Attribute | Returns: the attribute that was removedthe attribute to remove attribute)Removes an attribute from this element. |
| public Nodes | Returns: a list of all the children removed in the order they appeared in the elementDetaches all children from this node. |
| public void | removeNamespaceDeclaration(String
the prefix whose declaration should be removed prefix)Removes the mapping of the specified prefix. |
| public void | setBaseURI(String
the new base URI for this element URI)Implements abstract nu.
Sets the URI from which this element was loaded,
and against which relative URLs in this element will be
resolved, unless an |
| public void | |
| public void | setNamespacePrefix(String
the new namespace prefix prefix)Sets the namespace prefix of this element. |
| public void | |
| protected Element | Returns: an empty element with the same name and namespace as this elementCreates a very shallow copy of the element with the same name and namespace URI, but no children, attributes, base URI, or namespace declaration. |
| public String | Returns: a non-XML string representation of this elementOverrides java. Returns a string representation of this element suitable for debugging and diagnosis. |
| public final String | Returns: the XML representation of this elementImplements abstract nu. Returns a string containing the XML serialization of this element. |
| private static void | |
| private static void |
| attributes | back to summary |
|---|---|
| private Attribute[] attributes | |
| localName | back to summary |
|---|---|
| private String localName | |
| namespaces | back to summary |
|---|---|
| pack-priv Namespaces namespaces | |
| numAttributes | back to summary |
|---|---|
| private int numAttributes | |
| prefix | back to summary |
|---|---|
| private String prefix | |
| URI | back to summary |
|---|---|
| private String URI | |
| Element | back to summary |
|---|---|
| public Element(String name) Creates a new element in no namespace.
| |
| Element | back to summary |
|---|---|
| public Element(String name, String uri) Creates a new element in a namespace.
| |
| Element | back to summary |
|---|---|
| private Element() | |
| Element | back to summary |
|---|---|
| public Element(Element element) Creates a deep copy of an element. The copy is disconnected from the tree, and does not have a parent.
| |
| _setLocalName | back to summary |
|---|---|
| private void _setLocalName(String localName) | |
| _setNamespacePrefix | back to summary |
|---|---|
| private void _setNamespacePrefix(String prefix) | |
| _setNamespaceURI | back to summary |
|---|---|
| private void _setNamespaceURI(String uri) | |
| add | back to summary |
|---|---|
| private void add(Attribute attribute) | |
| addAttribute | back to summary |
|---|---|
| public void addAttribute(Attribute attribute) Adds an attribute to this element, replacing any existing attribute with the same local name and namespace URI.
| |
| addNamespaceDeclaration | back to summary |
|---|---|
| public void addNamespaceDeclaration(String prefix, String uri) Declares a namespace prefix. This is only necessary when prefixes are used in element content and attribute values, as in XSLT and the W3C XML Schema Language. Do not use this method to declare prefixes for element and attribute names. You can supply an empty string for the prefix to declare a default namespace, provided the element itself has a prefix. If you do redeclare a prefix that is already used by an element or attribute name, the additional namespace is added if and only if the URI is the same. Conflicting namespace declarations will throw an exception.
| |
| addPrefixIfNotAlreadyPresent | back to summary |
|---|---|
| private void addPrefixIfNotAlreadyPresent(HashMap<String, String> namespaces, Element current, String prefix) | |
| appendChild | back to summary |
|---|---|
| public void appendChild(String text) Converts a string to a text node and appends that node to the children of this node.
| |
| attributeIterator | back to summary |
|---|---|
| pack-priv Iterator | |
| build | back to summary |
|---|---|
| pack-priv static Element build(String name, String uri, String localName) | |
| checkCycle | back to summary |
|---|---|
| private static void checkCycle(Node child, ParentNode parent) | |
| checkPrefixConflict | back to summary |
|---|---|
| private void checkPrefixConflict(Attribute attribute) | |
| copy | back to summary |
|---|---|
| public Element copy() Implements abstract nu. Creates a deep copy of this element with no parent, that can be added to this document or a different one.
Subclassers should be wary. Implementing this method is trickier
than it might seem, especially if you wish to avoid potential
stack overflows in deep documents. In particular, you should not
rely on the obvious recursive algorithm. Most subclasses should
override the
| |
| copyAttributes | back to summary |
|---|---|
| private Attribute[] copyAttributes(Element newParent) | |
| copyChildren | back to summary |
|---|---|
| private static void copyChildren(final Element sourceElement, Element resultElement) | |
| copyTag | back to summary |
|---|---|
| private static Element copyTag(final Element source) | |
| escape | back to summary |
|---|---|
| private static String escape(String s) | |
| fastAddAttribute | back to summary |
|---|---|
| pack-priv void fastAddAttribute(Attribute attribute) | |
| getAttribute | back to summary |
|---|---|
| public final Attribute getAttribute(String name) Returns the attribute with the specified name in no namespace, or null if this element does not have an attribute with that name in no namespace. | |
| getAttribute | back to summary |
|---|---|
| public final Attribute getAttribute(String localName, String namespaceURI) Returns the attribute with the specified name and namespace URI, or null if this element does not have an attribute with that name in that namespace. | |
| getAttribute | back to summary |
|---|---|
| public final Attribute getAttribute(int index)
Selects an attribute by index.
The index is purely for convenience and has no particular
meaning. In particular, it is not necessarily the
position of this attribute in the original document from
which this
In general, you should not add attributes to or remove
attributes from the list while iterating across it.
Doing so will change the indexes of the other attributes in
the list. it is, however, safe to remove an attribute from
either end of the list (0 or
| |
| getAttributeCount | back to summary |
|---|---|
| public final int getAttributeCount()
Returns the number of attributes of this
| |
| getAttributeValue | back to summary |
|---|---|
| public final String getAttributeValue(String name) Returns the value of the attribute with the specified name in no namespace, or null if this element does not have an attribute with that name. | |
| getAttributeValue | back to summary |
|---|---|
| public final String getAttributeValue(String localName, String namespaceURI) Returns the value of the attribute with the specified name and namespace URI, or null if this element does not have such an attribute. | |
| getBaseURI | back to summary |
|---|---|
| public String getBaseURI() Overrides nu.
Returns the absolute base URI against which relative URIs in
this element should be resolved. This URI is made absolute before it is returned by resolving the information in this element against the information in its parent element and document entity. However, it is not always possible to fully absolutize the URI in all circumstances. In this case, this method returns the empty string to indicate the base URI of the current entity.
If the element's
| |
| getChildElements | back to summary |
|---|---|
| public final Elements getChildElements(String name) Returns a list of the child elements of this element with the specified name in no namespace. The elements returned are in document order. | |
| getChildElements | back to summary |
|---|---|
| public final Elements getChildElements(String localName, String namespaceURI) Returns a list of the immediate child elements of this element with the specified local name and namespace URI. Passing the empty string or null as the local name returns all elements in the specified namespace. Passing null or the empty string as the namespace URI returns elements with the specified name in no namespace. The elements returned are in document order. | |
| getChildElements | back to summary |
|---|---|
| public final Elements getChildElements() Returns a list of all the child elements of this element in document order.
| |
| getEntityURI | back to summary |
|---|---|
| private String getEntityURI() | |
| getFirstChildElement | back to summary |
|---|---|
| public final Element getFirstChildElement(String name) Returns the first child element with the specified name in no namespace. If there is no such element, it returns null. | |
| getFirstChildElement | back to summary |
|---|---|
| public final Element getFirstChildElement(String localName, String namespaceURI) Returns the first child element with the specified local name and namespace URI. If there is no such element, it returns null. | |
| getLocalName | back to summary |
|---|---|
| public final String getLocalName() Returns the local name of this element, not including the namespace prefix or colon.
| |
| getLocalNamespaceURI | back to summary |
|---|---|
| pack-priv final String getLocalNamespaceURI(String prefix) | |
| getNamespaceDeclarationCount | back to summary |
|---|---|
| public final int getNamespaceDeclarationCount()
Returns the number of namespace declarations on this
element. This counts the namespace of the element
itself (which may be the empty string), the namespace
of each attribute, and each namespace added
by
The return value is almost always positive. It can be zero
if and only if the element itself has the prefix
| |
| getNamespacePrefix | back to summary |
|---|---|
| public final String getNamespacePrefix() Returns the prefix of this element, or the empty string if this element does not have a prefix.
| |
| getNamespacePrefix | back to summary |
|---|---|
| public final String getNamespacePrefix(int index)
Returns the indexth namespace prefix declared on
this element. Namespaces inherited from ancestors are not included.
The index is purely for convenience, and has no
meaning in itself. This includes the namespaces of the element
name and of all attributes' names (except for those with the
prefix If the namespaces on the element change for any reason (adding or removing an attribute in a namespace, adding or removing a namespace declaration, changing the prefix of an element, etc.) then this method may skip or repeat prefixes. Don't change the prefixes of an element while iterating across them.
| |
| getNamespacePrefixes | back to summary |
|---|---|
| private Set | |
| getNamespacePrefixesInScope | back to summary |
|---|---|
| pack-priv Map | |
| getNamespaceURI | back to summary |
|---|---|
| public final String getNamespaceURI() Returns the namespace URI of this element, or the empty string if this element is not in a namespace.
| |
| getNamespaceURI | back to summary |
|---|---|
| public final String getNamespaceURI(String prefix) Returns the namespace URI mapped to the specified prefix within this element. Returns null if this prefix is not associated with a URI. | |
| getQualifiedName | back to summary |
|---|---|
| public final String getQualifiedName() Returns the complete name of this element, including the namespace prefix if this element has one.
| |
| getValue | back to summary |
|---|---|
| public final String getValue() Implements abstract nu. Returns the value of the element as defined by XPath 1.0. This is the complete PCDATA content of the element, without any tags, comments, or processing instructions after all entity and character references have been resolved.
| |
| grow | back to summary |
|---|---|
| private static int[] grow(int[] indexes, int top) | |
| insertChild | back to summary |
|---|---|
| public void insertChild(String text, int position) Converts a string to a text node and inserts that node at the specified position.
| |
| insertionAllowed | back to summary |
|---|---|
| pack-priv void insertionAllowed(Node child, int position) Implements abstract nu.
Inserts a child node at the specified position.
Inserting at position 0 makes the child the first child
of this node. Inserting at the position
All the other methods that add a node to the tree, invoke this method ultimately.
| |
| isElement | back to summary |
|---|---|
| pack-priv boolean isElement() Overrides nu. | |
| legalURI | back to summary |
|---|---|
| private boolean legalURI(String base) | |
| remove | back to summary |
|---|---|
| private boolean remove(Attribute attribute) | |
| removeAttribute | back to summary |
|---|---|
| public Attribute removeAttribute(Attribute attribute) Removes an attribute from this element.
| |
| removeChildren | back to summary |
|---|---|
| public Nodes removeChildren() Detaches all children from this node.
Subclassers should note that the default implementation of this
method does not call
| |
| removeNamespaceDeclaration | back to summary |
|---|---|
| public void removeNamespaceDeclaration(String prefix)
Removes the mapping of the specified prefix. This method only
removes additional namespaces added with
| |
| setBaseURI | back to summary |
|---|---|
| public void setBaseURI(String URI) Implements abstract nu.
Sets the URI from which this element was loaded,
and against which relative URLs in this element will be
resolved, unless an
| |
| setLocalName | back to summary |
|---|---|
| public void setLocalName(String localName) Sets the local name of this element.
| |
| setNamespacePrefix | back to summary |
|---|---|
| public void setNamespacePrefix(String prefix) Sets the namespace prefix of this element. You can pass null or the empty string to remove the prefix.
| |
| setNamespaceURI | back to summary |
|---|---|
| public void setNamespaceURI(String uri) Sets the namespace URI of this element.
| |
| shallowCopy | back to summary |
|---|---|
| protected Element shallowCopy()
Creates a very shallow copy of the element with the same name
and namespace URI, but no children, attributes, base URI, or
namespace declaration. This method is invoked as necessary
by the Subclasses should override this method so that it returns an instance of the subclass so that types are preserved when copying. This method should not add any attributes, namespace declarations, or children to the shallow copy. Any such items will be overwritten.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this element suitable for debugging and diagnosis. This is not the XML representation of the element.
| |
| toXML | back to summary |
|---|---|
| public final String toXML() Implements abstract nu. Returns a string containing the XML serialization of this element. This includes the element and all its attributes and descendants. However, it does not contain namespace declarations for namespaces inherited from ancestor elements.
| |
| writeEndTag | back to summary |
|---|---|
| private static void writeEndTag(Element element, StringBuilder result) | |
| writeStartTag | back to summary |
|---|---|
| private static void writeStartTag(Element element, StringBuilder result) | |
| Modifier and Type | Field and Description |
|---|---|
| private int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public Attribute | |
| public void | remove()
Overrides default java. |
| next | back to summary |
|---|---|
| private int next | |
| AttributeIterator | back to summary |
|---|---|
| private AttributeIterator() | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public Attribute next() throws NoSuchElementException Implements java. Doc from java. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the | |