Modifier and Type | Method and Description |
---|---|
Element |
addClassName(String... classNames)
Deprecated.
Deprecated in 5.4, as this is now special behavior for the "class" attribute.
|
Element |
attribute(String name,
String value)
Adds an attribute to the element, but only if the attribute name does not already exist.
|
Element |
attribute(String namespace,
String name,
String value)
Adds a namespaced attribute to the element, but only if the attribute name does not already exist.
|
Element |
attributes(String... namesAndValues)
Convenience for invoking
attribute(String, String) multiple times. |
CData |
cdata(String content)
Adds and returns a new CDATA node.
|
Element |
comment(String text)
Adds the comment and returns this element for further construction.
|
Element |
defineNamespace(String namespace,
String namespacePrefix)
Defines a namespace for this element, mapping a URI to a prefix.
|
Element |
element(String name,
String... namesAndValues)
Creates and returns a new Element node as a child of this node.
|
Element |
elementAt(int index,
String name,
String... namesAndValues)
Creates a new element, as a child of the current index, at the indicated index.
|
Element |
elementBefore(String name,
String... namesAndValues)
Inserts a new element before this element.
|
Element |
elementNS(String namespace,
String name)
Creates and returns a new Element within a namespace as a child of this node.
|
Element |
find(String path)
Searchs for a child element with a particular name below this element.
|
Element |
forceAttributes(String... namesAndValues)
Forces changes to a number of attributes.
|
Element |
forceAttributesNS(String namespace,
String... namesAndValues)
Forces changes to a number of attributes in the global namespace.
|
String |
getAttribute(String attributeName) |
Collection<Attribute> |
getAttributes()
Returns the attributes for this Element as a (often empty) collection of
Attribute s. |
String |
getChildMarkup() |
List<Node> |
getChildren()
Returns an unmodifiable list of children for this element.
|
Document |
getDocument() |
Element |
getElement(Predicate<Element> predicate)
Tries to find an element under this element (including itself) accepted by the given predicate.
|
Element |
getElementByAttributeValue(String attributeName,
String attributeValue)
Tries to find an element under this element (including itself) whose given attribute has a given value.
|
Element |
getElementById(String id)
Tries to find an element under this element (including itself) whose id is specified.
|
String |
getName() |
String |
getNamespace()
Returns the namespace for this element (which is typically a URL).
|
protected Map<String,String> |
getNamespaceURIToPrefix() |
boolean |
isEmpty()
Returns true if the element has no children, or has only text children that contain only whitespace.
|
void |
pop()
Removes an element; the element's children take the place of the node within its container.
|
Element |
raw(String text)
Adds the raw text and returns this element for further construction.
|
Element |
removeChildren()
Removes all children from this element.
|
Text |
text(String text)
Adds and returns a new text node (the text node is returned so that
Text.write(String) or [@link
Text.writef(String, Object[]) may be invoked . |
void |
visit(Visitor visitor)
Depth-first visitor traversal of this Element and its Element children.
|
getContainer, moveAfter, moveBefore, moveToBottom, moveToTop, remove, toMarkup, toString, wrap
public Document getDocument()
getDocument
in class Node
public Element attribute(String name, String value)
name
- the name of the attribute to addvalue
- the value for the attribute. A value of null is allowed, and no attribute will be added to the
element.public Element attribute(String namespace, String name, String value)
namespace
- the namespace to contain the attribute, or null for the default namespacename
- the name of the attribute to addvalue
- the value for the attribute. A value of null is allowed, and no attribute will be added to the
element.public Element attributes(String... namesAndValues)
attribute(String, String)
multiple times.namesAndValues
- alternating attribute names and attribute valuespublic Element forceAttributes(String... namesAndValues)
namesAndValues
- alternating attribute names and attribute valuespublic Element forceAttributesNS(String namespace, String... namesAndValues)
namespace
- the namespace or nullnamesAndValues
- alternating attribute name and valuepublic Element element(String name, String... namesAndValues)
name
- the name of the element to createnamesAndValues
- alternating attribute names and attribute valuespublic Element elementBefore(String name, String... namesAndValues)
name
- element namenamesAndValues
- attribute names and valuespublic Element elementNS(String namespace, String name)
namespace
- namespace to contain the element, or nullname
- element name to create within the namespacepublic Element elementAt(int index, String name, String... namesAndValues)
index
- to insert atname
- element namenamesAndValues
- attribute name / attribute value pairspublic Element comment(String text)
public Element raw(String text)
public Text text(String text)
Text.write(String)
or [@link
Text.writef(String, Object[])
may be invoked .text
- initial text for the nodepublic CData cdata(String content)
content
- the content to be rendered by the nodepublic Element getElementById(String id)
id
- the value of the id attribute of the element being looked forpublic Element getElementByAttributeValue(String attributeName, String attributeValue)
attributeName
- the name of the attribute of the element being looked forattributeValue
- the value of the attribute of the element being looked forpublic Element getElement(Predicate<Element> predicate)
predicate
- Predicate to accept the elementpublic Element find(String path)
public String getAttribute(String attributeName)
public Element addClassName(String... classNames)
classNames
- one or more CSS class namespublic Element defineNamespace(String namespace, String namespacePrefix)
xmlns:
attributes (to define
the namespace and prefix) to be rendered.namespace
- URI of the namespacenamespacePrefix
- prefixpublic String getNamespace()
public void pop()
public Element removeChildren()
protected Map<String,String> getNamespaceURIToPrefix()
getNamespaceURIToPrefix
in class Node
public boolean isEmpty()
public void visit(Visitor visitor)
visitor
- callbackpublic final String getChildMarkup()
Node.toString()
of its children.public List<Node> getChildren()
Element
s will
have children. Also, note that unlike W3C DOM, attributes are not represented as
Node
s.public Collection<Attribute> getAttributes()
Attribute
s. The order of the attributes within the collection is not specified.
Modifying the collection will not affect the attributes (use forceAttributes(String[])
to change
existing attribute values, and attribute(String, String, String)
to add new attribute values.${project.version} - Copyright © 2003-2015 The Apache Software Foundation.