public class XMLObject
extends java.lang.Object
implements java.io.Serializable
| Constructor and Description |
|---|
XMLObject()
Creates a new instance of XMLObject Some examples of usage // find first
instance of root2 to node in path 'element_root/root1/root2' XMLObject
xo1 = xo.findXMLObjectByPath("element_root/root1/root2"); // find index
instance of root3 to node in path 'element_root/root1/root2/root3' xo1 =
xo.findXMLObjectByPath("element_root/root1/root2/root3", 1); // get
attribute value for 'index' in 'element_root/root1/root2/root3' str =
xo.getAttribute("element_root/root1/root2/root3", "index"); // get
attribute value for 'index' in indexed 'element_root/root1/root2/root3'
str = xo.getAttribute("element_root/root1/root2/root3", 2, "index");
|
XMLObject(java.lang.String elementName) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAttribute(java.lang.String key,
int value) |
void |
addAttribute(java.lang.String key,
java.lang.String value) |
void |
addChild(int index,
XMLObject xmlObject) |
void |
addChild(XMLObject xmlObject) |
void |
addChildAfter(XMLObject before,
XMLObject xo) |
void |
addContent(java.lang.String content) |
XMLObject |
addNodeWithContent(java.lang.String nodeName,
java.lang.String content)
add a new node with the content as an child of this node.
|
int |
findChild(XMLObject xo) |
XMLObject |
findChildNode(java.lang.String nodeName)
Finds and returns a child XMLObject with nodeName or returns null if not
found
|
XMLObject |
findNode(XMLObject xo,
java.lang.String nodeName)
Finds and returns a XMLObject of nodeName or returns null if not found
Traverses node and subsequent child node searching for the nodeName.
|
XMLObject |
findXMLObjectByPath(java.lang.String path)
Using a path such as 'root/node1/node2' will return an XMLObject for
node2 if found else null.
|
XMLObject |
findXMLObjectByPath(java.lang.String path,
int index)
Using a path such as 'root/node1/node2' will return the index count of
node2.
|
java.lang.String |
getAttribute(java.lang.String path,
int index,
java.lang.String key)
Gets an attribute value as a string using path and key
|
java.lang.String |
getAttribute(java.lang.String path,
java.lang.String key)
Gets an attribute value as a string using path and key
|
java.lang.String |
getAttributeAsString(int index)
Get the attribute value for this index.
|
int |
getAttributeCount()
Get the number of attribute for this element.
|
java.lang.String |
getAttributeKeyAsString(int index)
Get the attribute key for this index.
|
java.util.List<XMLAttribute> |
getAttributes()
Get the list of attributes for this element.
|
java.lang.Object |
getAttributeValue(java.lang.String key)
Get the attribute value for this key, will return null if no key exists.
|
java.lang.String |
getAttributeValueAsString(java.lang.String key)
Get the attribute value for this key as a string, will return null if no
key exists.
|
java.lang.Object |
getAttributeValueNoNull(java.lang.String key)
Get the attribute value for this key as a string, will return "" if no
key exists.
|
XMLObject |
getChild(int index) |
int |
getChildCount() |
int |
getChildCount(java.lang.String childElementName)
Cound the number of children this XMLObject has that match the entered
childElementName (not case sensitive)
|
int |
getChildIndex(int from,
java.lang.String childElementName)
Get a child element starting a from index and containing childElementName
Will start at the entered from position getting each child element.
|
java.util.List<XMLObject> |
getChildren() |
java.lang.String |
getContent() |
java.lang.String |
getContent(java.lang.String path)
Gets content as a string using path to reach node.
|
java.lang.String |
getContent(java.lang.String path,
int index)
Gets content as a string using path and index to reach node.
|
java.lang.String |
getElementName() |
java.lang.String |
getName()
returns the element name including the namespace if there is one
|
java.lang.String |
getNameSpace() |
XMLObject |
getNode(java.lang.String path,
int index)
Gets a node and any children as a string using path and index
|
XMLObject |
getParent() |
XMLAttribute |
getXMLAttribute(int index) |
XMLAttribute |
getXMLAttribute(java.lang.String key) |
static void |
main(java.lang.String[] args) |
XMLObject |
mapXMLCharToXMLObject(java.lang.String xml)
Map an XML String to a XMLObject
|
XMLObject |
mapXMLCharToXMLObject(java.lang.String xml,
char[][] nameSpaces)
Map an XML String to a XMLObject
|
XMLObject |
mapXMLCharToXMLObject(java.lang.String xml,
java.lang.String nameSpace)
Map an XML String to a XMLObject
|
java.lang.String |
mapXMLObject2HTML() |
java.lang.String |
mapXMLObject2XML(XMLObject root)
Map an XMLObject to an XMLString
|
java.lang.String |
mapXMLObject2XML(XMLObject root,
boolean lineFeed)
Map an XMLObject to an XMLString
|
XMLObject |
mapXMLToXMLObject(java.lang.String xml)
Deprecated.
Please now use mapXMLCharToXMLObject()
|
void |
remove()
removes the xml object from it's parent if there is a parent.
|
void |
remove(XMLObject oldXO)
removes the xml object from it's parent if there is a parent
|
void |
removeChild(int index) |
void |
removeChild(XMLObject xo) |
void |
replace(XMLObject oldXO,
XMLObject newXO)
replaces the oldXO with the newXO by first determining the parent of the
oldXO and then replacing the child.
|
void |
setAttributes(java.util.List<XMLAttribute> attributes) |
void |
setElementName(java.lang.String elementName) |
void |
setNameSpace(java.lang.String nameSpace) |
protected void |
setup() |
java.lang.String |
toHTMLString() |
java.lang.String |
toString() |
java.lang.String |
toXMLString(boolean closeElement)
Converts the xml object into an XML String
|
java.lang.String |
toXMLString(int indent,
boolean closeElement)
Converts the xml object into an XML String
|
void |
updateAttribute(java.lang.String key,
java.lang.Object newValue) |
void |
updateAttribute(java.lang.String key,
java.lang.String newValue) |
void |
xmlAllNodes(XMLObject node,
XMLBuilder builder,
int indent,
boolean lineFeed) |
public XMLObject()
public XMLObject(java.lang.String elementName)
public java.lang.String getNameSpace()
public void setNameSpace(java.lang.String nameSpace)
protected void setup()
public void setElementName(java.lang.String elementName)
public void setAttributes(java.util.List<XMLAttribute> attributes)
public void addAttribute(java.lang.String key,
java.lang.String value)
public void addAttribute(java.lang.String key,
int value)
public void addContent(java.lang.String content)
public XMLObject addNodeWithContent(java.lang.String nodeName, java.lang.String content)
public java.lang.String getElementName()
public java.lang.String getName()
public XMLAttribute getXMLAttribute(int index)
public XMLAttribute getXMLAttribute(java.lang.String key)
public java.lang.Object getAttributeValue(java.lang.String key)
public java.lang.Object getAttributeValueNoNull(java.lang.String key)
public java.lang.String getAttributeValueAsString(java.lang.String key)
public java.lang.String getAttributeAsString(int index)
public java.lang.String getAttributeKeyAsString(int index)
public int getAttributeCount()
public java.util.List<XMLAttribute> getAttributes()
public void updateAttribute(java.lang.String key,
java.lang.String newValue)
public void updateAttribute(java.lang.String key,
java.lang.Object newValue)
public java.lang.String getContent()
public void addChild(XMLObject xmlObject)
public void addChild(int index,
XMLObject xmlObject)
public XMLObject getChild(int index)
public java.util.List<XMLObject> getChildren()
public int getChildIndex(int from,
java.lang.String childElementName)
from - is the index of the child that we want to start searching fromchildElementName - is the element we are looking forpublic void removeChild(int index)
public void removeChild(XMLObject xo)
public int getChildCount()
public int getChildCount(java.lang.String childElementName)
childElementName - only count elements that match this element namepublic XMLObject getParent()
public int findChild(XMLObject xo)
public XMLObject findNode(XMLObject xo, java.lang.String nodeName)
public XMLObject findChildNode(java.lang.String nodeName)
public void replace(XMLObject oldXO, XMLObject newXO)
oldXO - is the XMLObject to replacenewXO - is the XMLObject to replace it with.public void remove(XMLObject oldXO)
public void remove()
public java.lang.String getAttribute(java.lang.String path,
java.lang.String key)
throws java.lang.Exception
path - is the xml path to the node i.e. 'root/node1/node2'key - is the attribute value we want from the node.java.lang.Exceptionpublic java.lang.String getAttribute(java.lang.String path,
int index,
java.lang.String key)
throws java.lang.Exception
path - is the xml path to the node i.e. 'root/node1/node2'index - is the node2 index as child of node1.key - is the attribute value we want from the node.java.lang.Exceptionpublic XMLObject getNode(java.lang.String path, int index) throws java.lang.Exception
path - is the xml path to the node i.e. 'root/node1/node2'index - is the node2 index as child of node1.java.lang.Exceptionpublic java.lang.String getContent(java.lang.String path)
path - is the xml path to the node i.e. 'root/node1/node2'public java.lang.String getContent(java.lang.String path,
int index)
path - is the xml path to the node i.e. 'root/node1/node2'index - is the node2 index as child of node1.public XMLObject findXMLObjectByPath(java.lang.String path)
path - is the xml path such as 'root/node1/node2'public XMLObject findXMLObjectByPath(java.lang.String path, int index)
path - is the xml path such as 'root/node1/node2'index - is the index into last node name of pathpublic XMLObject mapXMLToXMLObject(java.lang.String xml) throws java.lang.Exception
java.lang.Exceptionpublic XMLObject mapXMLCharToXMLObject(java.lang.String xml)
public XMLObject mapXMLCharToXMLObject(java.lang.String xml, java.lang.String nameSpace)
xml - is the xml to mapnameSpace - will only map elements with this namespacepublic XMLObject mapXMLCharToXMLObject(java.lang.String xml, char[][] nameSpaces)
xml - is the xml to mapnameSpaces - will only map elements with these namespacespublic java.lang.String mapXMLObject2XML(XMLObject root)
public java.lang.String mapXMLObject2XML(XMLObject root, boolean lineFeed)
public void xmlAllNodes(XMLObject node, XMLBuilder builder, int indent, boolean lineFeed)
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toHTMLString()
public java.lang.String mapXMLObject2HTML()
public java.lang.String toXMLString(boolean closeElement)
closeElement - if set true will terminate the node using either '/>' or
'</elementName>'. if set false will close the node with
'>' provided no content has been added.public java.lang.String toXMLString(int indent,
boolean closeElement)
indent - is the indenting spaces to add at the beginning of the xmlcloseElement - if set true will terminate the node using either '/>' or
'</elementName>'. if set false will close the node with
'>' provided no content has been added.public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception