Package ucar.unidata.xml
Class XmlUtil
java.lang.Object
ucar.unidata.xml.XmlUtil
- Direct Known Subclasses:
XmlEncoder
A collection of utilities for xml.
- Author:
- IDV development team
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addChildren
(Element element, List children) Append the given list of children Elements to the given Element.static void
appendCdata
(StringBuffer sb, String s) _more_static void
appendCdataBytes
(StringBuffer sb, byte[] bytes) _more_static void
attr
(Appendable buff, String name, String value, String tab) Append onto the given StringBuffer name="value" string encode the value.static String
Return a String with name="value".static String
_more_static String
_more_static String
Return a String with n1="v1invalid input: '"' n2="v2invalid input: '"'.static String
Return a String with n1="v1invalid input: '"' n2="v2invalid input: '"'.static String
Return a String with n1="v1invalid input: '"' n2="v2invalid input: '"'.static String
calculateRFC2104HMAC
(String data, String key) Computes RFC 2104-compliant HMAC signature.static String
Make a close tagstatic String
Create and return an xml comment.static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static Element
_more_static void
createCDataNode
(Element parent, String text) _more_static byte[]
Decode the given base64 Stringstatic XmlUtil.ElementListIterator
_more_static String
encodeBase64
(byte[] b) Return the base64 encoded representation of the given byte arraystatic String
Do a simple conversion of special characters to their encoding.static void
ensureAttributes
(Node element, String[] attrs) Make sure that the given element contains the given attributes.static NodeList
_more_static XPathExpression
_more_static Element
findAncestor
(Element child, String tagName) Find the ancestor of the given node with the given tagnamestatic Element
Find the first child element of the given parent Node whose tag name.equals the given tag.static Element
findChildRecurseUp
(Node parent, String tag) Find the first child element of the given parent Node whose tag name.equals the given tag.static List
findChildren
(Node parent, String tag) Find all of the children elements of the given parent Node whose tag name.equals the given tag.static List
findChildrenRecurseUp
(Node parent, String tag) Find all of the children elements of the given parent Node and all of its ancestors whose tag name.equals the given tag.static Element
findDescendant
(Node parent, String tag) Find the first descendant element of the given parent Node whose tag name.equals the given tag.static Element
findDescendantFromPath
(Element parent, String path) This method searches, starting at the given parent, for a descendant path.static List
findDescendants
(Node parent, String tag) Find all of the descendant elements of the given parent Node whose tag name.equals the given tag.static List
findDescendantsFromPath
(Element parent, String path) Like findDescendantFromPath, this method finds all descendants.static Element
findElement
(Element root, String tag, String attributeName, String attributeValue) Find the Element under (recursively) the given root Element with the given tag name (if non-null) that contains an attribute of the given name and value.static Element
findElement
(NodeList elements, String attributeName, String attributeValue) Find the first Element in the given NodeList of Elements that has the given attribute with value .equals the given attributeValue.static Element
Find the root element of the given node.static Element
findUrlRefNode
(Element node) This method will return either the given node argument if it does not contain an attribute of name "url".static Element
findUrlRefNode
(Element node, String urlAttr) This method will return either the given node argument if it does not contain an attribute of the given urlAttr.static String
getAttribute
(NamedNodeMap attrs, String name) Get the given name-d attribute from the given attrs map.static boolean
getAttribute
(NamedNodeMap attrs, String name, boolean dflt) Get the given name-d attribute from the given attrs map.static double
getAttribute
(NamedNodeMap attrs, String name, double dflt) Get the given name-d attribute from the given attrs map.static float
getAttribute
(NamedNodeMap attrs, String name, float dflt) Get the given name-d attribute from the given attrs map.static int
getAttribute
(NamedNodeMap attrs, String name, int dflt) Get the given name-d attribute from the given attrs map.static Color
getAttribute
(NamedNodeMap attrs, String name, Color dflt) Get the given name-d attribute from the given attrs map.static String
getAttribute
(NamedNodeMap attrs, String name, String dflt) Get the given name-d attribute from the given attrs map.static String
getAttribute
(Node element, String name) Get the given name attribute from the given element.static boolean
getAttribute
(Node element, String name, boolean dflt) Get the given name-d attribute from the given element.static double
getAttribute
(Node element, String name, double dflt) Get the given name-d attribute from the given element.static float
getAttribute
(Node element, String name, float dflt) Get the given name-d attribute from the given element.static int
getAttribute
(Node element, String name, int dflt) Get the given name-d attribute from the given element.static Color
getAttribute
(Node element, String name, Color dflt) Get the given name-d attribute from the given element.static String
getAttribute
(Node element, String name, String dflt) Get the given name-d attribute from the given element.static String
getAttributeFromTree
(Node element, String name) Get the given named attribute from the given element.static boolean
getAttributeFromTree
(Node element, String name, boolean dflt) _more_static int
getAttributeFromTree
(Node element, String name, int dflt) Get the given named attribute from the given element.static String
getAttributeFromTree
(Node element, String name, String dflt) Get the given named attribute from the given element.static List
getAttributesFromTree
(Node element, String name, Hashtable tags) Get a list of attributes of the given name from the given element and all of its parent elements.static List
getAttributesFromTree
(Node element, String name, Hashtable tags, List listOfValues) Get a list of attributes of the given name from the given element and all of its parent elements.static String
_more_static String
getChildText
(Node parent) Concatenates the node values (grom getNodeValue) of the children of the given parent Node.static Document
getDocument
(InputStream stream) Create a Document object with the given xml.static Document
getDocument
(String xml) Create a Document object with the given xml.static Document
getDocument
(String filename, Class originClass) Read in the xml contained in the given filename, parse it and return the root Element.static Element
getElement
(Element parent, String tagName) Get the first Element children of the given parent Element with the given tagName.static NodeList
getElements
(Element parent) Get all children of the given parent Element who are instances of the Element class.static XmlNodeList
getElements
(Element parent, String tagName) Get all Element children of the given parent Element with the given tagName.static NodeList
getElements
(Element parent, XmlNodeList nodeList) Get all children of the given parent Element who are instances of the Element class.static Element
getFirstChild
(Element parent) Get the first Element child of the given parent Element.static NodeList
getGrandChildren
(Element parent) Get all grand children of the given parent Element who are instances of the Element class.static String
getGrandChildText
(Node parent, String childTag) Finds the child node with the given tag name.static String
getGrandChildText
(Node parent, String childTag, String dflt) Finds the child node with the given tag name.static double
getGrandChildValue
(Node parent, String childTag, double dflt) _more_static String
Return the default xml header.static List
getListOfElements
(Element parent) Create and return a List of the Element children of the given parent node.static String
getLocalName
(Node element) Get the non qualified tag namestatic String
getNodeName
(Node node) Get the non qualified tag namestatic Element
getRoot
(InputStream stream) Read in the xml contained in the given filename, parse it and return the root Element.static Element
Parse the given xml and return the root Element.static Element
Read in the xml contained in the given filename, parse it and return the root Element.static boolean
hasAttribute
(Node element, String attributeName) Does the given node have the attributestatic boolean
isFullyQualified
(String tagName) _more_static boolean
Checks if the tag name of the given node matches the given name.static Document
_more_static void
A main for testsstatic CDATASection
makeCDataNode
(Document doc, String text) _more_static CDATASection
makeCDataNode
(Document doc, String text, boolean andEncode) _more_static Document
A utility to make an empty documentstatic void
mergeAttributes
(Element n1, Element n2) Copy the attributes from n2 to n1.static String
Make an open tagstatic String
Return a String of the form: <name attrs />static String
Wrap the given string value in quotes.static void
removeChildren
(Element parent) Remove all children from the given parent Element.static void
setAttribute
(Element node, String name, Color value) A utility to set the attribute on the given node as the String representation of the given colorstatic void
setAttributes
(Element node, String[] attrs) The attrs parameter is an array of [name1, value1, name2, value2, etc].static String
Return a String of the form: <name attrs />static String
Return a String of the form: <name attrs > contents </name>static void
toHtml
(StringBuffer html, Node node) _more_static String
Convert the DOM rooted at the given Node to an xml String representation.static String
Convert the DOM rooted at the given Node to an xml String representation.static void
toString
(Node node, Appendable appendable) _more_static String
Convert the DOM rooted at the given Node to an xml representation.static String
Convert the DOM rooted at the given Node to an xml representation.static String
toStringNoChildren
(Node node) Convert the DOM rooted at the given Node to an xml String representation.static String
toStringWithHeader
(Node node) Convert the DOM rooted at the given Node to an xml String representation.static String
toStringWithHeader
(Node node, String tabSpacing, String newLine) Convert the DOM rooted at the given Node to an xml representation.static String
toStringWithHeader
(Node node, String tabSpacing, String newLine, boolean prettifyAttrs) Convert the xml to a string.
-
Field Details
-
XML_HEADER
The header to use when writing out xml- See Also:
-
TAG_WILDCARD
used for matching any tag- See Also:
-
NULL_STRING
Just so we don't have to do (String) null.
-
-
Constructor Details
-
XmlUtil
public XmlUtil()Dummy ctor for doclint.
-
-
Method Details
-
quote
Wrap the given string value in quotes.- Parameters:
value
- the String to wrap in quotes.- Returns:
- The given string argument in quotes.
-
encodeBase64
Return the base64 encoded representation of the given byte array- Parameters:
b
- The bytes to encode- Returns:
- The encoded string
-
decodeBase64
Decode the given base64 String- Parameters:
s
- Holds the base64 encoded bytes- Returns:
- The decoded bytes
-
comment
Create and return an xml comment.- Parameters:
value
- The String to comment.- Returns:
- The value argument wrapped in an xml comment.
-
attr
Append onto the given StringBuffer name="value" string encode the value.- Parameters:
buff
- The string buffer to append onto.name
- The attribute name.value
- The attribute value.tab
- The tab to prepend onto the result.
-
attr
Return a String with name="value". Encode the value.- Parameters:
name
- The attribute name.value
- The attribute value.- Returns:
- The string "name=value"
-
attrs
_more_- Parameters:
attrs
- _more_- Returns:
- _more_
-
attrs
_more_- Parameters:
name
- _more_value
- _more_- Returns:
- _more_
-
attrs
Return a String with n1="v1invalid input: '"' n2="v2invalid input: '"'.- Parameters:
n1
- The first attribute name.v1
- The first attribute value.n2
- The second attribute name.v2
- The second attribute value.- Returns:
- The attrbiute string.
-
attrs
Return a String with n1="v1invalid input: '"' n2="v2invalid input: '"'. n3="v3invalid input: '"'.- Parameters:
n1
- The first attribute name.v1
- The first attribute value.n2
- The second attribute name.v2
- The second attribute value.n3
- The third attribute name.v3
- The third attribute value.- Returns:
- The attrbiute string.
-
attrs
public static String attrs(String n1, String v1, String n2, String v2, String n3, String v3, String n4, String v4) Return a String with n1="v1invalid input: '"' n2="v2invalid input: '"'. n3="v3invalid input: '"'. n4="v4invalid input: '"'.- Parameters:
n1
- The first attribute name.v1
- The first attribute value.n2
- The second attribute name.v2
- The second attribute value.n3
- The third attribute name.v3
- The third attribute value.n4
- The fourth attribute name.v4
- The fourth attribute value.- Returns:
- The attrbiute string.
-
tag
Return a String of the form: <name attrs > contents </name>- Parameters:
name
- The tag name.attrs
- The attribute section of the tag.contents
- The body of the tag- Returns:
- The return xml.
-
tag
Return a String of the form: <name attrs />- Parameters:
name
- The tag name.attrs
- The attribute section of the tag.- Returns:
- The return xml.
-
openTag
Return a String of the form: <name attrs />- Parameters:
name
- The tag name.attrs
- The attribute section of the tag.- Returns:
- The return xml.
-
openTag
Make an open tag- Parameters:
name
- tag name- Returns:
- the open tag
-
closeTag
Make a close tag- Parameters:
name
- tag name- Returns:
- the tag
-
getAttributeFromTree
Get the given named attribute from the given element. If not found then recursively look in the parent of the given element. If the attribute is finally not found then null is returned.- Parameters:
element
- The xml node to look within.name
- The attribute name- Returns:
- The value of the given attribute or null if not found.
-
getAttributeFromTree
Get the given named attribute from the given element. If not found then recursively look in the parent of the given element. If the attribute is finally not found then the dflt argument is returned.- Parameters:
element
- The xml node to look within.name
- The attribute name.dflt
- The default value returned.- Returns:
- The value of the given attribute or dflt if not found.
-
getAttributeFromTree
Get the given named attribute from the given element. If not found then recursively look in the parent of the given element. If the attribute is finally not found then the dflt argument is returned. If it is found then convert the string value to an integer.- Parameters:
element
- The xml node to look within.name
- The attribute name.dflt
- The default value returned.- Returns:
- The integer value of the attribute or the dflt if the attribute is not found.
-
getAttributeFromTree
_more_- Parameters:
element
- _more_name
- _more_dflt
- _more_- Returns:
- _more_
-
getAttributesFromTree
Get a list of attributes of the given name from the given element and all of its parent elements.- Parameters:
element
- The xml node to look within.name
- The attribute name.tags
- If non-null then only look at elements whose tag name is held by the tags hashtable. If the element we are looking at is not within the table then stop searching upwards.- Returns:
- The list of attribute values.
-
getAttributesFromTree
public static List getAttributesFromTree(Node element, String name, Hashtable tags, List listOfValues) Get a list of attributes of the given name from the given element and all of its parent elements.- Parameters:
element
- The xml node to look within.name
- The attribute name.tags
- If non-null then only look at elements whose tag name is held by the tags hashtable. If the element we are looking at is not within the table then stop searching upwards.listOfValues
- The list ot put the values in.- Returns:
- The list of attribute values.
-
hasAttribute
Does the given node have the attribute- Parameters:
element
- nodeattributeName
- attribute- Returns:
- has attribute
-
getAttribute
Get the given name attribute from the given element. If the attribute is not found this will throw an IllegalArgumentException- Parameters:
element
- The xml element to look within.name
- The attribute name.- Returns:
- The value of the attribute.
-
ensureAttributes
Make sure that the given element contains the given attributes. If the element does not contain all of the given attribute names then an IllegalArgumentException is thrown.- Parameters:
element
- The xml element to look within.attrs
- Array of attribute names.
-
getAttribute
Get the given name-d attribute from the given element. If not found return the dflt argument.- Parameters:
element
- The xml element to look within.name
- The attribute name.dflt
- The default value.- Returns:
- The attribute value or the dflt if not found.
-
getAttribute
Get the given name-d attribute from the given element. Convert it into a boolean. If not found return the dflt argument.- Parameters:
element
- The xml element to look within.name
- The attribute name.dflt
- The default value.- Returns:
- The boolean attribute value or the dflt if not found.
-
getAttribute
Get the given name-d attribute from the given element. Convert it into an int. If not found return the dflt argument.- Parameters:
element
- The xml element to look within.name
- The attribute name.dflt
- The default value.- Returns:
- The int attribute value or the dflt if not found.
-
getAttribute
Get the given name-d attribute from the given element. Convert it into a float. If not found return the dflt argument.- Parameters:
element
- The xml element to look within.name
- The attribute name.dflt
- The default value.- Returns:
- The float attribute value or the dflt if not found.
-
getAttribute
Get the given name-d attribute from the given element. Convert it into a double. If not found return the dflt argument.- Parameters:
element
- The xml element to look within.name
- The attribute name.dflt
- The default value.- Returns:
- The double attribute value or the dflt if not found.
-
getAttribute
Get the given name-d attribute from the given element. Convert it into a Color. If not found return the dflt argument.- Parameters:
element
- The xml element to look within.name
- The attribute name.dflt
- The default value.- Returns:
- The Color attribute value or the dflt if not found.
-
getAttribute
Get the given name-d attribute from the given attrs map. If not found then throw an IllegalArgumentException.- Parameters:
attrs
- The xml attribute map.name
- The name of the attribute.- Returns:
- The attribute value.
-
getAttribute
Get the given name-d attribute from the given attrs map. If not found then return the dflt argument.- Parameters:
attrs
- The xml attribute map.name
- The name of the attribute.dflt
- The default value- Returns:
- The attribute valueif found, else the dflt argument.
-
getAttribute
Get the given name-d attribute from the given attrs map. If found convert it to int. If not found then return the dflt argument.- Parameters:
attrs
- The xml attribute map.name
- The name of the attribute.dflt
- The default value- Returns:
- The attribute valueif found, else the dflt argument.
-
getAttribute
Get the given name-d attribute from the given attrs map. If found convert it to float. If not found then return the dflt argument.- Parameters:
attrs
- The xml attribute map.name
- The name of the attribute.dflt
- The default value- Returns:
- The attribute valueif found, else the dflt argument.
-
getAttribute
Get the given name-d attribute from the given attrs map. If found convert it to double. If not found then return the dflt argument.- Parameters:
attrs
- The xml attribute map.name
- The name of the attribute.dflt
- The default value- Returns:
- The attribute valueif found, else the dflt argument.
-
getAttribute
Get the given name-d attribute from the given attrs map. If found convert it to boolean. If not found then return the dflt argument.- Parameters:
attrs
- The xml attribute map.name
- The name of the attribute.dflt
- The default value- Returns:
- The attribute valueif found, else the dflt argument.
-
getAttribute
Get the given name-d attribute from the given attrs map. If found convert it to Color (GuiUtils.decodeColor(java.lang.String, java.awt.Color)
). If not found then return the dflt argument.- Parameters:
attrs
- The xml attribute map.name
- The name of the attribute.dflt
- The default value- Returns:
- The attribute valueif found, else the dflt argument.
-
setAttribute
A utility to set the attribute on the given node as the String representation of the given color- Parameters:
node
- The nodename
- The attr namevalue
- The color
-
mergeAttributes
Copy the attributes from n2 to n1.- Parameters:
n1
- The source of the attributes.n2
- What to copy into.
-
setAttributes
The attrs parameter is an array of [name1, value1, name2, value2, etc]. Set these attributes on the given node.- Parameters:
node
- The xml element to set attributes on.attrs
- The array of attribute name/value pairs.
-
findChild
Find the first child element of the given parent Node whose tag name.equals the given tag. Return null if not found.- Parameters:
parent
- The xml node to search for children.tag
- The tag name of the child xml element.- Returns:
- The child found or null if not found.
-
findChildrenRecurseUp
Find all of the children elements of the given parent Node and all of its ancestors whose tag name.equals the given tag.- Parameters:
parent
- The xml node to search for children.tag
- The tag name of the child xml element.- Returns:
- The List of children
-
findChildRecurseUp
Find the first child element of the given parent Node whose tag name.equals the given tag. If not found then recursively search up the ancestors of the parent.- Parameters:
parent
- The xml node to search for children.tag
- The tag name of the child xml element.- Returns:
- The child found or null if not found.
-
findChildren
Find all of the children elements of the given parent Node whose tag name.equals the given tag. Return an empty list if none found.- Parameters:
parent
- The xml node to search for children.tag
- The tag name of the child xml element.- Returns:
- The list of children that match the given tag name.
-
addChildren
Append the given list of children Elements to the given Element.- Parameters:
element
- The parent element.children
- The list of children.
-
findDescendant
Find the first descendant element of the given parent Node whose tag name.equals the given tag.- Parameters:
parent
- The root of the xml dom tree to search.tag
- The tag name to match.- Returns:
- The element foudn or null
-
findDescendants
Find all of the descendant elements of the given parent Node whose tag name.equals the given tag.- Parameters:
parent
- The root of the xml dom tree to search.tag
- The tag name to match.- Returns:
- The list of descendants that match the given tag.
-
findDescendantFromPath
This method searches, starting at the given parent, for a descendant path. The path is defined by the "." delimited path string. Each token in the path is a tag name.So, given:
path=Alabama.Alaska.Arkansas
this method will try to find the Arkansas tag which is a child of Alaska, which is a child of Alabama, which is a child of the given parent parameter.- Parameters:
parent
- The root of the xml dom tree to search.path
- The "." delimited string of tag names.- Returns:
- The list of descendants that are under the given path.
-
findDescendantsFromPath
Like findDescendantFromPath, this method finds all descendants.- Parameters:
parent
- The root of the xml dom tree to search.path
- The "." delimited string of tag names.- Returns:
- The list of descendants that are under the given path.
-
getRoot
Parse the given xml and return the root Element.- Parameters:
xml
- The xml.- Returns:
- The root of the xml dom.
- Throws:
Exception
- When something goes wrong.
-
create
_more_- Parameters:
tag
- _more_parent
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
_more_- Parameters:
tag
- _more_parent
- _more_attrs
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
_more_- Parameters:
doc
- _more_tag
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
_more_- Parameters:
doc
- _more_tag
- _more_parent
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
_more_- Parameters:
doc
- _more_tag
- _more_parent
- _more_attrs
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
_more_- Parameters:
doc
- _more_tag
- _more_attrs
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
public static Element create(Document doc, String tag, Element parent, String[] attrs) throws Exception _more_- Parameters:
doc
- _more_tag
- _more_parent
- _more_attrs
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
public static Element create(Document doc, String tag, Element parent, String text, String[] attrs) throws Exception _more_- Parameters:
doc
- _more_tag
- _more_parent
- _more_text
- _more_attrs
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
public static Element create(Document doc, String tag, Element parent, String text) throws Exception _more_- Parameters:
doc
- _more_tag
- _more_parent
- _more_text
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
_more_- Parameters:
tag
- _more_parent
- _more_attrs
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
public static Element create(String tag, Element parent, String text, String[] attrs) throws Exception _more_- Parameters:
tag
- _more_parent
- _more_text
- _more_attrs
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
create
_more_- Parameters:
tag
- _more_parent
- _more_text
- _more_- Returns:
- _more_
- Throws:
Exception
- _more_
-
getRoot
Read in the xml contained in the given filename, parse it and return the root Element. If the filename cannot be found then return null- Parameters:
filename
- The filename, url or resource path of the xml document.originClass
- Where to look for resources.- Returns:
- The root of the xml dom.
- Throws:
Exception
- When something goes wrong.
-
getRoot
Read in the xml contained in the given filename, parse it and return the root Element.- Parameters:
stream
- _more_- Returns:
- The root of the xml dom.
- Throws:
Exception
- When something goes wrong.
-
getDocument
Read in the xml contained in the given filename, parse it and return the root Element.- Parameters:
filename
- The filename, url or resource path of the xml document.originClass
- Where to look for resources.- Returns:
- The root of the xml dom.
- Throws:
Exception
- When something goes wrong.
-
findRoot
Find the root element of the given node.- Parameters:
child
- The xml element to serach for the root of.- Returns:
- The root of the DOM tree that the given child exists in.
-
isTag
Checks if the tag name of the given node matches the given name. If the given name is fully qualified (e.g., namespace:tagname) then check if it matches the full name of the node. If the node name is fully qualified and the name isn't then strip off the namespace of the node and compare else just compare the 2- Parameters:
node
- the xml nodename
- name- Returns:
- is non qualified tag name the same
-
getLocalName
Get the non qualified tag name- Parameters:
element
- element- Returns:
- tag name
-
isFullyQualified
_more_- Parameters:
tagName
- _more_- Returns:
- _more_
-
getNodeName
Get the non qualified tag name- Parameters:
node
- node- Returns:
- node name
-
findAncestor
Find the ancestor of the given node with the given tagname- Parameters:
child
- The xml element to serach for the root of.tagName
- The tag name to look for- Returns:
- The ancestor
-
makeDocument
A utility to make an empty document- Returns:
- An empty document.
-
getDocument
Create a Document object with the given xml.- Parameters:
xml
- The xml.- Returns:
- A new Document.
- Throws:
Exception
- When something goes wrong.
-
getDocument
Create a Document object with the given xml.- Parameters:
stream
- stream- Returns:
- A new Document.
- Throws:
Exception
- When something goes wrong.
-
getFirstChild
Get the first Element child of the given parent Element.- Parameters:
parent
- The xml node to search its chidlren.- Returns:
- The first child of the given node or null if there are none.
-
getElements
Get all children of the given parent Element who are instances of the Element class.- Parameters:
parent
- The xml node to search its chidlren.- Returns:
- All Element children of the given parent.
-
getElements
Get all children of the given parent Element who are instances of the Element class.- Parameters:
parent
- The xml node to search its chidlren.nodeList
- list to add to- Returns:
- All Element children of the given parent.
-
getGrandChildren
Get all grand children of the given parent Element who are instances of the Element class.- Parameters:
parent
- The xml node to search its chidlren.- Returns:
- All Element children of the given parent.
-
getGrandChildText
Finds the child node with the given tag name. Then gets the child text from that node if it is non-null.- Parameters:
parent
- The xml node to search its chidlren.childTag
- _more_dflt
- _more_- Returns:
- The text values contained by the children of the given parent.
-
getGrandChildValue
_more_- Parameters:
parent
- _more_childTag
- _more_dflt
- _more_- Returns:
- _more_
-
getGrandChildText
Finds the child node with the given tag name. Then gets the child text from that node if it is non-null.- Parameters:
parent
- The xml node to search its chidlren.childTag
- _more_- Returns:
- The text values contained by the children of the given parent.
-
appendCdataBytes
_more_- Parameters:
sb
- _more_bytes
- _more_
-
appendCdata
_more_- Parameters:
sb
- _more_s
- _more_
-
getCdata
_more_- Parameters:
s
- _more_- Returns:
- _more_
-
makeCDataNode
_more_- Parameters:
doc
- _more_text
- _more_- Returns:
- _more_
-
createCDataNode
_more_- Parameters:
parent
- _more_text
- _more_
-
makeCDataNode
_more_- Parameters:
doc
- _more_text
- _more_andEncode
- _more_- Returns:
- _more_
-
getChildText
Concatenates the node values (grom getNodeValue) of the children of the given parent Node.- Parameters:
parent
- The xml node to search its chidlren.- Returns:
- The text values contained by the children of the given parent.
-
getElements
Get all Element children of the given parent Element with the given tagName.- Parameters:
parent
- The xml node to search its children.tagName
- The tag to match.- Returns:
- The Element children of the given parent node whose tags match the given tagName.
-
getElement
Get the first Element children of the given parent Element with the given tagName.- Parameters:
parent
- The xml node to search its children.tagName
- The tag to match.- Returns:
- The first Element child that matches the given tag name.
-
getListOfElements
Create and return a List of the Element children of the given parent node.- Parameters:
parent
- The xml node to find its children.- Returns:
- List of children Elements.
-
getHeader
Return the default xml header.- Returns:
- The default xml document header.
-
toString
Convert the DOM rooted at the given Node to an xml String representation.- Parameters:
node
- The xml node to convert its tree.- Returns:
- The String representation of the node's tree.
-
toStringNoChildren
Convert the DOM rooted at the given Node to an xml String representation.- Parameters:
node
- The xml node to convert its tree.- Returns:
- The String representation of the node's tree.
-
toStringWithHeader
Convert the DOM rooted at the given Node to an xml String representation. Prepend the xml header.- Parameters:
node
- The xml node to convert its tree.- Returns:
- The String representation of the node's tree.
-
toString
Convert the DOM rooted at the given Node to an xml String representation.- Parameters:
node
- The xml node to convert its tree.prettyPrint
- Should the string be formatted with tabs and new lines- Returns:
- The String representation of the node's tree.
-
toString
Convert the DOM rooted at the given Node to an xml representation. Use the given tabSpacing to include spacing within the hierarchy.- Parameters:
node
- The xml tree root.tabSpacing
- The spacing to put into the result string before each tag.newLine
- The new line to output after each tag.- Returns:
- The String representation of the node's tree.
-
toString
Convert the DOM rooted at the given Node to an xml representation. Use the given tabSpacing to include spacing within the hierarchy.- Parameters:
node
- The xml tree root.tabSpacing
- The spacing to put into the result string before each tag.newLine
- The new line to output after each tag.recurse
- _more_- Returns:
- The String representation of the node's tree.
-
toStringWithHeader
Convert the DOM rooted at the given Node to an xml representation. Use the given tabSpacing to include spacing within the hierarchy. Prepend the xml header to the text.- Parameters:
node
- The xml tree root.tabSpacing
- The spacing to put into the result string before each tag.newLine
- The new line to output after each tag.- Returns:
- The String representation of the node's tree.
-
toString
_more_- Parameters:
node
- _more_appendable
- _more_
-
toStringWithHeader
public static String toStringWithHeader(Node node, String tabSpacing, String newLine, boolean prettifyAttrs) Convert the xml to a string. Add the xml header- Parameters:
node
- xml roottabSpacing
- tabnewLine
- new lineprettifyAttrs
- If true then layout attributes- Returns:
- String representation of the given xml node
-
toHtml
_more_- Parameters:
html
- _more_node
- _more_
-
encodeString
Do a simple conversion of special characters to their encoding.- Parameters:
v
- The source string.- Returns:
- The encoded String.
-
findElement
Find the first Element in the given NodeList of Elements that has the given attribute with value .equals the given attributeValue.- Parameters:
elements
- The Elements to search.attributeName
- The attribute name to look for.attributeValue
- The value to match.- Returns:
- The Element in the elements list that has an attribute of the given name with the given value.
-
findElement
public static Element findElement(Element root, String tag, String attributeName, String attributeValue) Find the Element under (recursively) the given root Element with the given tag name (if non-null) that contains an attribute of the given name and value.- Parameters:
root
- The Element to seatrch under.tag
- The tag name of the descendant Element to match.attributeName
- The attribute name to look for.attributeValue
- The value to match.- Returns:
- The descendant Element that has an attribute of the given name with the given value.
-
removeChildren
Remove all children from the given parent Element.- Parameters:
parent
- The xml element to remove children from.
-
findUrlRefNode
This method will return either the given node argument if it does not contain an attribute of the given urlAttr. Or it will return the parsed document specified by the value of the urlAttr contained by node.- Parameters:
node
- The node to look at.urlAttr
- The attribute name that holds the url.- Returns:
- The root of the new document or the given node argument if no url ref found.
-
findUrlRefNode
This method will return either the given node argument if it does not contain an attribute of name "url". Or it will return the parsed document specified by the value of the urlAttr contained by node.- Parameters:
node
- The node to look at.- Returns:
- The root of the new document or the given node argument if no url ref found.
-
main
A main for tests- Parameters:
args
- Command line arguments- Throws:
Exception
- _more_
-
calculateRFC2104HMAC
Computes RFC 2104-compliant HMAC signature.- Parameters:
data
- The data to be signed.key
- The signing key.- Returns:
- The base64-encoded RFC 2104-compliant HMAC signature.
- Throws:
SignatureException
- when signature generation fails
-
elements
_more_- Parameters:
xmlFile
- _more_xPath
- _more_
-
eval
_more_- Parameters:
xmlFile
- _more_xPath
- _more_
-
loadXml
_more_- Parameters:
xmlFile
- _more_
-
expr
_more_- Parameters:
xPath
- _more_
-