@NotThreadSafe
public class XMLElement
extends Object
Instances of this class are not thread safe.
| Modifier and Type | Class and Description |
|---|---|
static interface |
XMLElement.Factory
Factory.
|
static interface |
XMLElement.Handler
Handler.
|
| Constructor and Description |
|---|
XMLElement(String name)
Constructs an instance.
|
XMLElement(String name,
Object... contents)
Constructs an instance.
|
| Modifier and Type | Method and Description |
|---|---|
XMLElement |
addChild(String name)
Adds a child.
|
void |
addChild(XMLElement child)
Adds a child.
|
void |
addText(String text)
Adds the element's text.
|
boolean |
containsAttribute(String name)
Asks if this element contains a specified attribute.
|
XMLElement |
copy()
Creates a copy of this element.
|
protected void |
disownChildren()
Disowns the children.
|
boolean |
equals(Object other) |
static String |
escape(CharSequence text,
char quote)
Escapes protected characters.
|
int |
getAttributeCount()
Gets the attributes count.
|
List<XMLAttribute> |
getAttributes()
Gets the element's attributes.
|
Optional<String> |
getAttributeValue(String name,
Optional<String> defaultValue)
Gets an attribute's value by its name.
|
XMLElement |
getChild(int index)
Gets the element's child at an index.
|
int |
getChildCount()
Gets the child count.
|
Set<? extends String> |
getChildNames()
Gets the element's child names.
|
List<? extends XMLElement> |
getChildren()
Gets the element's children.
|
List<? extends XMLElement> |
getChildren(String name)
Gets the element's children with a specific name.
|
XMLElement.Factory |
getFactory()
Gets the xml element factory.
|
Optional<XMLElement> |
getFirstChild(String name)
Gets the first child element with a specific name.
|
String |
getName()
Gets this element's name.
|
Optional<? extends XMLElement> |
getParent()
Gets the parent.
|
String |
getPath()
Gets the path.
|
String |
getText()
Gets the element's text.
|
int |
hashCode() |
boolean |
isNameEmpty()
Asks if the name is empty.
|
void |
removeAttribute(String attributeName)
Removes an element's attribute.
|
void |
setAttribute(String attributeName,
boolean attributeValue)
Sets an element's attribute.
|
void |
setAttribute(String attributeName,
Optional<String> attributeValue)
Sets an element's attribute.
|
void |
setAttribute(String attributeName,
String attributeValue)
Sets an element's attribute.
|
void |
setAttribute(XMLAttribute attribute)
Sets an element's attribute.
|
void |
setName(String elementName)
Sets the element's name.
|
String |
toString() |
public XMLElement(@Nonnull
String name)
Note: this constructor is needed by some script langauges.
name - The element's name.public XMLElement(@Nonnull
String name,
@Nonnull
Object... contents)
name - The element's name.contents - The element's contents.@Nonnull
@CheckReturnValue
public static String escape(@Nonnull
CharSequence text,
char quote)
text - The source text.quote - The quote character ('"', '\'' or '\0').@Nonnull public XMLElement addChild(@Nonnull String name)
name - The name of the child.public void addChild(@Nonnull
XMLElement child)
child - The child.public final void addText(@Nonnull
String text)
text - Some text.@CheckReturnValue
public boolean containsAttribute(@Nonnull
String name)
name - The name of the attribute.@Nonnull @CheckReturnValue public XMLElement copy()
public boolean equals(Object other)
equals in class Object@CheckReturnValue public final int getAttributeCount()
@Nonnull
@CheckReturnValue
public Optional<String> getAttributeValue(@Nonnull
String name,
@Nonnull
Optional<String> defaultValue)
name - The name of the attribute.defaultValue - The value to return if the attribute is not present.@Nonnull @CheckReturnValue public final List<XMLAttribute> getAttributes()
@Nonnull @CheckReturnValue public XMLElement getChild(int index)
index - An origin 0 index;@CheckReturnValue public final int getChildCount()
@Nonnull @CheckReturnValue public Set<? extends String> getChildNames()
@Nonnull @CheckReturnValue public List<? extends XMLElement> getChildren()
@Nonnull @CheckReturnValue public List<? extends XMLElement> getChildren(@Nonnull String name)
name - The children's name.@Nonnull @CheckReturnValue public XMLElement.Factory getFactory()
@Nonnull @CheckReturnValue public final Optional<XMLElement> getFirstChild(@Nonnull String name)
name - The child name.@Nonnull @CheckReturnValue public final String getName()
@Nonnull @CheckReturnValue public final Optional<? extends XMLElement> getParent()
@Nonnull @CheckReturnValue public final String getPath()
@Nonnull @CheckReturnValue public String getText()
public int hashCode()
hashCode in class Object@CheckReturnValue public final boolean isNameEmpty()
public final void removeAttribute(@Nonnull
String attributeName)
attributeName - The attribute name.public final void setAttribute(@Nonnull
XMLAttribute attribute)
attribute - The attribute.public final void setAttribute(@Nonnull
String attributeName,
boolean attributeValue)
attributeName - The attribute name.attributeValue - The attribute value.public final void setAttribute(@Nonnull
String attributeName,
@Nonnull
Optional<String> attributeValue)
attributeName - The attribute name.attributeValue - The attribute value (empty means remove).public final void setAttribute(@Nonnull
String attributeName,
@Nonnull
String attributeValue)
attributeName - The attribute name.attributeValue - The attribute value.public final void setName(@Nonnull
String elementName)
elementName - The element's name.public final String toString()
toString in class Objectprotected final void disownChildren()
Copyright © 2003-2019 Serge Brisson. All Rights Reserved.