public class Dnode extends Object
It removes support for nodes being mixed with content. That is, a node can only contain content or a list of one or more child nodes. It does not support mixing bits of content between the child nodes.
Although designed to simplify XML in supported cases it can be used as a general tree structure with attributes of java Objects.
| Constructor and Description |
|---|
Dnode()
Create a node.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChild(Dnode child)
Add a child.
|
Iterator<String> |
attributeNames()
The attribute names as strings.
|
List<Dnode> |
children()
List of children nodes.
|
Dnode |
find(String nodeName)
Find the first matching node using nodeName.
|
Dnode |
find(String nodeName,
String attrName,
Object value)
Find the first node matching nodeName and attribute value.
|
Dnode |
find(String nodeName,
String attrName,
Object value,
int maxLevel)
Search for a single node with control over maxLevel.
|
List<Dnode> |
findAll(String nodeName,
int maxLevel)
Find all the nodes that match the nodeName.
|
List<Dnode> |
findAll(String nodeName,
String attrName,
Object value,
int maxLevel)
Find all the nodes that match the nodeName and attribute value.
|
StringBuilder |
generate(StringBuilder sb)
Generate this node as xml to the buffer.
|
String |
getAttribute(String name)
Return the attribute for a given name.
|
int |
getChildrenCount()
Return the number of children this node has.
|
int |
getLevel()
Return the level or depth of the node from the root.
|
String |
getNodeContent()
Return the node content.
|
String |
getNodeName()
Return the node name.
|
String |
getStringAttr(String name,
String defaultValue)
Returns an Attribute as a String.
|
boolean |
hasChildren()
Return true if this node has children.
|
static Dnode |
parse(String s)
Parse the raw XML string.
|
boolean |
remove(Dnode node)
Remove a ancestor node.
|
void |
setAttribute(String name,
String value)
Set an attribute.
|
void |
setLevel(int level)
Set the level or depth of this node from the root.
|
void |
setNodeContent(String nodeContent)
Set the node content.
|
void |
setNodeName(String nodeName)
Set the node name.
|
String |
toString() |
String |
toXml()
Return the node as XML.
|
public String toXml()
public StringBuilder generate(StringBuilder sb)
public String getNodeName()
public void setNodeName(String nodeName)
public String getNodeContent()
public void setNodeContent(String nodeContent)
public boolean hasChildren()
public int getChildrenCount()
public boolean remove(Dnode node)
public void addChild(Dnode child)
public int getLevel()
public void setLevel(int level)
public Dnode find(String nodeName)
public Dnode find(String nodeName, String attrName, Object value)
public Dnode find(String nodeName, String attrName, Object value, int maxLevel)
public List<Dnode> findAll(String nodeName, int maxLevel)
public List<Dnode> findAll(String nodeName, String attrName, Object value, int maxLevel)
public String getStringAttr(String name, String defaultValue)
Will throw a ClassCastException if the attribute is not a String.
Copyright © 2014. All Rights Reserved.