XmlItem.Type
Modifier and Type | Field and Description |
---|---|
static Element[] |
EMPTY_ARRAY |
protected static java.lang.String |
NAMESPACE_PREFIX |
protected static java.lang.String |
NAMESPACE_SEPARATOR |
Constructor and Description |
---|
Element()
Initialize the new instance with default values.
|
Element(java.lang.String tagName)
Initialize the new instance with the given name.
|
Element(java.lang.String tagName,
java.lang.String text)
Initialize the new instance with the given name and text.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(Element childElement)
Adds the given element as a child to the receiver
|
void |
addChildItem(XmlItem item)
Adds the given item as a child to the receiver.
|
protected java.util.List<Element> |
collect(IElementFilter elementFilter,
boolean recursive)
Returns all elements with the given tag name.
|
protected java.util.List<Element> |
collectContainedElements() |
protected Element[] |
collectElements(java.lang.String tagName,
java.util.Map<java.lang.String,java.lang.String> attributes,
boolean all) |
Element |
copy()
Returns a copy of the element with all child elements copied as well.
|
Element |
deepCopy()
Returns a deep copy of the element.
|
protected java.util.Map<java.lang.String,java.lang.String> |
detectNamespaceDeclarations() |
Element[] |
find(IElementFilter filter)
Returns all sub elements matching the given filter.
|
Element[] |
find(java.lang.String tagName)
Returns all sub elements with the given tag name plus this element,
if it's name is equal to the given tagName.
|
Element[] |
find(java.lang.String tagName,
java.util.Map<java.lang.String,java.lang.String> attributes)
Returns all sub elements with the given tag name and the specified
attribute values plus this element if it matches the tagName and
attributes.
|
Element[] |
findChildren(java.lang.String tagName)
Returns all children with the given tag name.
|
Element[] |
findChildren(java.lang.String tagName,
java.util.Map<java.lang.String,java.lang.String> attributes)
Returns all children with the given tag name and the specified
attribute values.
|
Element |
findFirst(IElementFilter filter)
Returns the first element in the hierarchy that matches the given filter
or null if none matches.
|
Element[] |
findSubElements(java.lang.String tagName)
Returns all sub elements with the given tag name.
|
Element[] |
findSubElements(java.lang.String tagName,
java.util.Map<java.lang.String,java.lang.String> attributes)
Returns all sub elements with the given tag name and the specified
attribute values.
|
java.lang.String |
getAttribute(java.lang.String attrName)
Returns the value of the attribute with the given name.
|
java.lang.String[] |
getAttributeLocalNames()
Returns the names of all attributes assigned to this element.
|
java.lang.String[] |
getAttributeNames()
Returns the names of all attributes assigned to this element.
|
protected java.lang.String[] |
getAttributeNames(boolean withPrefix) |
java.util.Map<java.lang.String,java.lang.String> |
getAttributes()
Returns all attributes of this element.
|
int |
getChildItemCount()
Returns the number of contained child items.
|
XmlItem[] |
getChildItems()
Returns all children of all types.
|
Element[] |
getChildren()
Returns all direct child elements.
|
Element[] |
getChildren(IElementFilter elementFilter)
Returns all direct child elements that match the given filter.
|
Element[] |
getChildren(java.lang.String tagName)
Returns all direct child elements with the given tagName.
|
int |
getChildrenCount()
Returns the number of child elements.
|
protected NamedTextList |
getElementAttributes() |
Element |
getFirstChild()
Returns the first direct child element or null if there is no child element.
|
Element |
getFirstChild(IElementFilter elementFilter)
Returns the first child element that matches the given filter
or null if there is no matching child element found.
|
Element |
getFirstChild(java.lang.String tagName)
Returns the first child element that matches the given filter
or null if there is no matching child element found.
|
protected java.util.List<XmlItem> |
getInternalChildItems() |
XmlItem.Type |
getItemType()
Returns always Type.ELEMENT.
|
java.lang.String |
getLocalName()
Returns the local name of this element.
|
protected java.lang.String |
getLocalNameOf(java.lang.String aName) |
java.lang.String |
getName()
Returns the name of the element.
|
java.lang.String |
getNamePrefix() |
protected java.lang.String |
getNamePrefixOf(java.lang.String aName) |
java.util.Map<java.lang.String,java.lang.String> |
getNamespaceDeclarations()
Returns a map with the names of namespaces as keys and the corresponding
namespace URIs as values.
|
protected java.util.Map<java.lang.String,java.lang.String> |
getNamespaces() |
java.lang.String |
getText()
Returns the elements textual content which corresponds to the
XML tag's PCDATA.
|
boolean |
hasAttribute(java.lang.String attrName)
Returns true if the element has an attribute with the given name.
|
boolean |
hasAttributes()
Returns true if the element has any attribute.
|
boolean |
hasChildItems()
Returns true if the element has any child (Element or
XmlProcessingInstruction ). |
boolean |
hasChildren()
Returns true if the element contains at least on child element.
|
boolean |
hasProcessingInstructions()
Returns true if the element contains at least one processing instruction.
|
boolean |
hasText()
Returns true if the element has any text.
|
protected int |
indexOfChild(XmlItem child) |
protected void |
insertAfter(int index,
XmlItem item)
Inserts the given child after the given index
|
protected void |
insertBefore(int index,
XmlItem item)
Inserts the given child before the given index
|
boolean |
insertChildAfter(XmlItem oldChild,
XmlItem newChild)
Inserts the given newChild after the specified old child.
|
boolean |
insertChildBefore(XmlItem oldChild,
XmlItem newChild)
Inserts the given newChild before the specified old child.
|
protected boolean |
matches(Element element,
java.lang.String tagName,
java.util.Map<java.lang.String,java.lang.String> attributes) |
void |
removeAllChildren()
Removes all children of this element.
|
void |
removeAttribute(java.lang.String attrName)
Removes the attribute with the specified name from the element's
attribute list.
|
boolean |
removeChild(Element childElement)
Removes the given child from this element.
|
boolean |
removeChildItem(XmlItem item)
Removes the given child from this element.
|
void |
removeText()
Removes the element's text content.
|
boolean |
replaceChild(XmlItem oldChild,
XmlItem newChild)
Replaces the given oldChild by the given newChild.
|
void |
setAttribute(java.lang.String attrName,
java.lang.String value)
Sets the value of the attribute with the given name.
|
protected void |
setAttributes(NamedTextList newValue) |
protected void |
setChildItems(java.util.List<XmlItem> items) |
void |
setName(java.lang.String newName)
Set the element's name which corresponds to its XML tag name.
|
protected void |
setNamespaces(java.util.Map<java.lang.String,java.lang.String> newValue) |
void |
setText(java.lang.String newText)
Set the element's text.
|
Element |
shallowCopy()
Returns a shallow copy of the element, that is a new element with the same
name, same attributes and same text but without children.
|
protected StringUtil |
str() |
static Element[] |
toArray(java.util.Collection<Element> elementCollection)
Returns an Element array that contains all Element objects of the given
collection.
|
static java.util.List<Element> |
toList(Element[] elements)
Returns an ArrayList that contains all elements of the given array.
|
java.lang.String |
toString()
Returns the element's name as a XML tag.
|
public static final Element[] EMPTY_ARRAY
protected static final java.lang.String NAMESPACE_SEPARATOR
protected static final java.lang.String NAMESPACE_PREFIX
public Element()
public Element(java.lang.String tagName)
tagName
- The name of the new elementpublic Element(java.lang.String tagName, java.lang.String text)
tagName
- The name of the new elementtext
- The text content of the new elementpublic static Element[] toArray(java.util.Collection<Element> elementCollection)
elementCollection
- The collection to be converted to an array.java.lang.ClassCastException
- If any object in the given collection is not an Element.public static java.util.List<Element> toList(Element[] elements)
elements
- The array to convert to a listpublic XmlItem.Type getItemType()
getItemType
in interface XmlItem
public java.lang.String getName()
public void setName(java.lang.String newName)
newName
- Any valid XML tag namepublic java.lang.String getLocalName()
public java.lang.String getNamePrefix()
public java.lang.String getText()
public void setText(java.lang.String newText)
newText
- Any valid XML character data compliant to the desired encodingpublic java.lang.String getAttribute(java.lang.String attrName)
attrName
- The name of the attribute including a namespace prefix if applicablepublic void setAttribute(java.lang.String attrName, java.lang.String value)
attrName
- The name of the attribute including a namespace prefix if applicablevalue
- The value to assign to this attributepublic void removeAttribute(java.lang.String attrName)
attrName
- The name of the attribute to remove (including namespace prefix)public java.util.Map<java.lang.String,java.lang.String> getAttributes()
public java.lang.String[] getAttributeNames()
public java.lang.String[] getAttributeLocalNames()
public int getChildItemCount()
public int getChildrenCount()
public Element[] getChildren()
public Element[] getChildren(java.lang.String tagName)
public Element[] getChildren(IElementFilter elementFilter)
public Element getFirstChild()
public Element getFirstChild(java.lang.String tagName)
public Element getFirstChild(IElementFilter elementFilter)
public boolean hasChildItems()
XmlProcessingInstruction
).
For more specific item types see hasChildren()
and hasProcessingInstructions()
.public boolean hasChildren()
public boolean hasProcessingInstructions()
public boolean removeChild(Element childElement)
childElement
- The child element to be removedpublic boolean removeChildItem(XmlItem item)
item
- The child element to be removedpublic void removeAllChildren()
Element
and XmlProcessingInstruction
).public void removeText()
public boolean hasText()
public boolean hasAttributes()
public boolean hasAttribute(java.lang.String attrName)
public java.lang.String toString()
toString
in class java.lang.Object
public void addChild(Element childElement)
childElement
- The element to addpublic void addChildItem(XmlItem item)
item
- The item to add.public boolean insertChildAfter(XmlItem oldChild, XmlItem newChild)
public boolean insertChildBefore(XmlItem oldChild, XmlItem newChild)
public boolean replaceChild(XmlItem oldChild, XmlItem newChild)
public Element findFirst(IElementFilter filter)
filter
- The filter that defines which elements match (must not be null).public Element[] find(IElementFilter filter)
filter
- The filter that defines which elements match (must not be null).public Element[] find(java.lang.String tagName)
public Element[] find(java.lang.String tagName, java.util.Map<java.lang.String,java.lang.String> attributes)
tagName
- The name of the elements to be found (must not be null).attributes
- Definition of attributes the elements must match (may be null).public Element[] findSubElements(java.lang.String tagName)
public Element[] findSubElements(java.lang.String tagName, java.util.Map<java.lang.String,java.lang.String> attributes)
public Element[] findChildren(java.lang.String tagName)
public Element[] findChildren(java.lang.String tagName, java.util.Map<java.lang.String,java.lang.String> attributes)
public Element shallowCopy()
public Element deepCopy()
public Element copy()
deepCopy()
public java.util.Map<java.lang.String,java.lang.String> getNamespaceDeclarations()
public XmlItem[] getChildItems()
protected java.util.List<Element> collect(IElementFilter elementFilter, boolean recursive)
protected Element[] collectElements(java.lang.String tagName, java.util.Map<java.lang.String,java.lang.String> attributes, boolean all)
protected void setChildItems(java.util.List<XmlItem> items)
protected boolean matches(Element element, java.lang.String tagName, java.util.Map<java.lang.String,java.lang.String> attributes)
protected java.util.Map<java.lang.String,java.lang.String> detectNamespaceDeclarations()
protected int indexOfChild(XmlItem child)
protected void insertAfter(int index, XmlItem item)
protected void insertBefore(int index, XmlItem item)
protected java.lang.String[] getAttributeNames(boolean withPrefix)
protected java.lang.String getNamePrefixOf(java.lang.String aName)
protected java.lang.String getLocalNameOf(java.lang.String aName)
protected java.util.List<XmlItem> getInternalChildItems()
protected java.util.List<Element> collectContainedElements()
protected NamedTextList getElementAttributes()
protected void setAttributes(NamedTextList newValue)
protected java.util.Map<java.lang.String,java.lang.String> getNamespaces()
protected void setNamespaces(java.util.Map<java.lang.String,java.lang.String> newValue)
protected StringUtil str()