public class NanoXmlUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
stClassName |
protected static java.lang.String |
stVersion |
Constructor and Description |
---|
NanoXmlUtils() |
Modifier and Type | Method and Description |
---|---|
static XMLElement |
createNewXMLElement(java.lang.String name)
Returns new XMLElement(new Hashtable(), true, false);
|
static XMLElement |
deepClone(XMLElement root)
Gets a copy of the complete tree
|
static java.lang.String |
escapeChars(java.lang.String stInput)
Replaces special characters with their html code in the passed String
|
static java.lang.String |
getAllAttributes(XMLElement elem,
boolean replaceHref)
Calls getAllAttributes(elem, replaceHref, false);
|
static java.lang.String |
getAllAttributes(XMLElement elem,
boolean replaceHref,
boolean escapeChars)
Returns all attributes as a String in the following format:
name1="value1"
name2="value2"
|
static XMLElement |
getChildByName(XMLElement parent,
java.lang.String name,
int nr)
Gets a child of a XMLElement by name and sibling number
|
static XMLElement |
getCopy(XMLElement elem,
boolean withAttributes)
Get a copy of a XMLElement.
|
static XMLElement |
getElementByXpath(XMLElement rootElement,
java.lang.String xPath)
Gets an XMLElement by its XPath
ex: /Envelope/Body/ObjList/Item[2]
where Item[2] is the second sibling with tagname Item
if no sibling is specified, x = 1 is assumed
|
static java.util.Vector |
getElements(XMLElement xElem,
boolean onlyLeafs,
java.util.Vector vElem)
Returns all elements or only leaf elements.
|
static java.util.Vector |
getElementsByAttribute(XMLElement xElem,
java.lang.String attrName,
java.lang.String attrValue,
java.util.Vector vElem)
Returns all elements that contain a certain attribute with
possibly a certain value.
|
static java.util.Vector |
getElementsByChildName(XMLElement xElem,
java.lang.String childName,
java.lang.String childContent,
boolean onlyChildren,
java.util.Vector vElem)
Returns all elements that have children with a certain name and
possibly a certain content.
|
static java.util.Vector |
getElementsByName(XMLElement xElem,
java.lang.String name,
java.util.Vector vElem)
Returns all elements with a certain Name.
|
static java.lang.String |
getLastError()
Gets the last error that occurred
|
static java.lang.String |
getLocalPart(java.lang.String stQName)
Gets the local part of the qualified name
|
static java.lang.String |
getVersion()
Returns the version of the class.
|
static XMLElement |
parseString(java.lang.String s)
Calls new XMLElement(new Hashtable(), true, false) and
tries to parse the String into it.
|
static java.lang.String |
removeXmlDeclaration(java.lang.String xml)
Removes the XML declaration if found
|
static XMLElement |
replaceAttributes(XMLElement root)
Returns a new XML structure after turning attributes into child elements
|
static XMLElement |
replaceHref(XMLElement root)
Returns a new XML structure after replacing multi-references
|
static int |
setAllAttributes(XMLElement elem,
java.lang.String attributes)
Sets attributes from a String in the following format:
name1="value1"\nname2="value2"
|
static java.lang.String |
toPrettyString(XMLElement root)
Gets a pretty formatted String representation of a XML structure
|
protected static java.lang.String stVersion
protected static java.lang.String stClassName
public static XMLElement createNewXMLElement(java.lang.String name)
name
- The name of the new XMLElement. When null, it is set to ""public static XMLElement deepClone(XMLElement root)
root
- The root element of the source treepublic static java.lang.String escapeChars(java.lang.String stInput)
stInput
- The input Stringpublic static java.lang.String getAllAttributes(XMLElement elem, boolean replaceHref)
elem
- The XMLElementreplaceHref
- If true, then href and id attributes are not returnedpublic static java.lang.String getAllAttributes(XMLElement elem, boolean replaceHref, boolean escapeChars)
name1="value1" name2="value2"
elem
- The XMLElementreplaceHref
- If true, then href and id attributes are not returnedescapeChars
- If true, attribute values are escapedpublic static XMLElement getChildByName(XMLElement parent, java.lang.String name, int nr)
parent
- The parent XMLElementname
- The tag name of the childnr
- The sibling number, where 1 is the first siblingpublic static XMLElement getCopy(XMLElement elem, boolean withAttributes)
elem
- The source elementwithAttributes
- If false, no attributes are returnedpublic static XMLElement getElementByXpath(XMLElement rootElement, java.lang.String xPath)
rootElement
- The root element of the XML structurexPath
- The XPath to the elementpublic static java.util.Vector getElements(XMLElement xElem, boolean onlyLeafs, java.util.Vector vElem)
xElem
- The XMLElement to start withonlyLeafs
- When true, only returns leaf elementsvElem
- The output Vector of XMLElements (when null a new Vector is created)
When not null, found elements are added to the Vectorpublic static java.util.Vector getElementsByAttribute(XMLElement xElem, java.lang.String attrName, java.lang.String attrValue, java.util.Vector vElem)
xElem
- The XMLElement to start withattrName
- The name of the attribute to checkattrValue
- The Value of the attribute, use null if value should not be checkedvElem
- The output Vector of XMLElements (when null a new Vector is created)
When not null, found elements are added to the Vectorpublic static java.util.Vector getElementsByChildName(XMLElement xElem, java.lang.String childName, java.lang.String childContent, boolean onlyChildren, java.util.Vector vElem)
xElem
- The XMLElement to start with. Must not be null.childName
- The name of the child element(s). Must not be nullchildContent
- The content of the child, use null if content should not be checked (in this case,
the child might also be a group element with childs of its own)onlyChildren
- If true, only children are checked. If false, all descendants are checked.vElem
- The output Vector of XMLElements (when null a new Vector is created)
When not null, found elements are added to the Vectorpublic static java.util.Vector getElementsByName(XMLElement xElem, java.lang.String name, java.util.Vector vElem)
xElem
- The XMLElement to start withname
- The name of the elementvElem
- The output Vector of XMLElements (when null a new Vector is created)
When not null, found elements are added to the Vectorpublic static java.lang.String getLastError()
public static java.lang.String getLocalPart(java.lang.String stQName)
stQName
- The qualified namepublic static java.lang.String getVersion()
public static XMLElement parseString(java.lang.String s)
s
- The String to parsepublic static java.lang.String removeXmlDeclaration(java.lang.String xml)
xml
- The original Stringpublic static XMLElement replaceAttributes(XMLElement root)
root
- The root element to work on recursivelypublic static XMLElement replaceHref(XMLElement root)
root
- The root element to work on recursivelypublic static int setAllAttributes(XMLElement elem, java.lang.String attributes)
elem
- The XMLElementattributes
- The String containing the attributespublic static java.lang.String toPrettyString(XMLElement root)
root
- The root element