public class Element extends Object implements XMLNode
Currently this does not support CDataSection
| Modifier and Type | Field and Description |
|---|---|
protected LinkedList<Pair<String,String>> |
attributes |
protected LinkedList<XMLNode> |
children |
protected String |
defxmlns |
protected String |
name |
protected String |
xmlns |
| Constructor and Description |
|---|
Element(Element element)
Performs a deep copy on the supplied element and populates instance
variable of this instance.
|
Element(String name)
Creates a blank element with the name given
|
Element(String name,
String text)
Creates a simple element with given and name and text value
|
Element(String name,
StringBuilder[] attributeName,
StringBuilder[] attributeValues)
Public Constructor to instantiate Element
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAttribute(String attName,
String attValue) |
void |
addAttributes(Map<String,String> attrs) |
void |
addCDATASection(String cdata)
Adds
CDataSection node in the children of this element |
void |
addChild(XMLNode child) |
void |
addChildren(List<Element> children) |
void |
addText(String text)
Adds text node in the children of this element.
|
void |
addText(String text,
boolean removeExiting)
adds
Text node to this element children. |
int |
children()
Returns number of children for this node.
|
Element |
clone()
makes a deep copy of this XML Node and returns it
|
boolean |
equals(Object obj) |
Element |
findChild(String[] elemPath) |
<R> List<R> |
flatMapChildren(Function<Element,Collection<? extends R>> mapper) |
void |
forEachChild(Consumer<Element> consumer) |
String |
getAttribute(String attName)
Returns value for the supplied attribute.
|
List<Pair<String,String>> |
getAttributes()
Returns attributes for this element.
|
Element |
getChild(String name) |
Element |
getChild(String name,
String child_xmlns) |
String |
getChildAttribute(String childName,
String attName) |
List<Element> |
getChildren() |
List<Element> |
getChildren(String[] elementPath) |
Element |
getChildStaticStr(String name) |
String |
getName() |
String |
getXMLNS() |
String |
getXMLNS(String[] elementPath) |
void |
removeAttribute(String key) |
boolean |
removeChild(Element child) |
void |
removeText()
Removes
Text nodes and CDataSection nodes from the
children of this element |
void |
setAttribute(String key,
String value) |
void |
setChildren(List<XMLNode> children) |
void |
setDefXMLNS(String ns) |
void |
setName(String argName) |
void |
setXMLNS(String ns) |
String |
stringify()
Returns XML representation of this XML node
|
String |
stringifyChildren()
Returns XML string with all the children nodes of this node
|
String |
toString() |
String |
val()
Returns concatenated String of
Text and CDataSection
nodes in the children. |
protected String name
protected String defxmlns
protected String xmlns
protected LinkedList<XMLNode> children
protected LinkedList<Pair<String,String>> attributes
public Element(String name)
name - element namepublic Element(String name, String text)
name - element nametext - string value of the elementpublic Element(String name, StringBuilder[] attributeName, StringBuilder[] attributeValues)
name - name of the elementattributeName - array of attribute namesattributeValues - array of attribute valuespublic Element(Element element)
element - element isntance from which this element will be clonedpublic void addChild(XMLNode child)
public <R> List<R> flatMapChildren(Function<Element,Collection<? extends R>> mapper)
public String getAttribute(String attName)
Map if this degrades the performance. The assumption is that XMPP
packets do not have too many attributes.attName - attribute namepublic List<Pair<String,String>> getAttributes()
Pairs in which first value is attribute name
and second is attribute valuepublic String getXMLNS()
public void removeAttribute(String key)
public boolean removeChild(Element child)
public void addText(String text)
CDataSection and Text nodes from the
childrentext - String value for this elementpublic void addText(String text, boolean removeExiting)
Text node to this element children. If
removeExisting flag is on, exisitng CDataSection and
Text nodes will be removedtext - String value of this elementremoveExiting - a flag indicating if the exisitng value should be
removedpublic void removeText()
Text nodes and CDataSection nodes from the
children of this elementpublic void addCDATASection(String cdata)
CDataSection node in the children of this elementcdata - CDATA content Stringpublic void setDefXMLNS(String ns)
public void setName(String argName)
public void setXMLNS(String ns)
public String getName()
public int children()
XMLNodepublic String stringify()
XMLNodepublic String stringifyChildren()
XMLNodestringifyChildren in interface XMLNodepublic Element clone()
XMLNodepublic String val()
XMLNodeText and CDataSection
nodes in the children. If there is no child of type Text or
CDataSection exist, this method will return nullCopyright © 2019. All rights reserved.