public class XMLUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COPYRIGHT |
static java.lang.String |
VERSION |
Constructor and Description |
---|
XMLUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
collectElements(java.lang.StringBuilder aXMLBuffer,
java.lang.String aTypeRegex,
boolean aIsPrefix,
boolean aIgnoreCase,
boolean aRemove,
java.util.Collection aCollection)
Collects (as Strings) all elements from the XML String that have types matching the regex in the first argument.
|
static java.lang.StringBuffer |
encode(java.lang.String string)
Deprecated.
|
static java.lang.StringBuffer |
encode(java.lang.StringBuffer in)
Encode the xml special characters "<",">","'",""","&".
|
static java.lang.StringBuilder |
encode(java.lang.StringBuilder in)
Encode the xml special characters "<",">","'",""","&".
|
static java.lang.String |
encodeString(java.lang.String in)
Encode the xml special characters "<",">","'",""","&".
|
static org.w3c.dom.Node |
findNode(org.w3c.dom.Element aElement,
java.lang.String aNodeType,
java.util.Map<java.lang.String,java.lang.String> aAttributeMap)
Finds the "first" node in the children of an Element that matches the input criteria.
|
static org.w3c.dom.Node |
findNode(org.w3c.dom.Element aElement,
java.lang.String aNodeType,
java.lang.String aAttrKey,
java.lang.String aAttrValue)
Finds the "first" node in the children of an Element that matches the input criteria.
|
static java.util.List |
getAllAttributes(org.w3c.dom.Element aNode)
Return all attributes of the given element node.
|
static java.util.List |
getAllChildElements(org.w3c.dom.Element aNode)
Return all child elements of the given element node.
|
static java.util.Map<java.lang.String,java.lang.String> |
getAttributesFromTag(java.lang.String aTag)
Obtains a mapping of attribute keys and values from an XML or HTML tag
|
static java.util.Map<java.lang.String,java.lang.String> |
getAttributesFromTag(java.lang.String aTag,
boolean isHTML)
Obtains a mapping of attribute keys and values from an XML or HTML tag
|
static java.lang.String |
getAttributeValue(org.w3c.dom.Element aNode,
java.lang.String aAttrName)
Return the string value of the named attribute.
|
static java.lang.String |
getAttributeValue(org.w3c.dom.Element aNode,
java.lang.String aNamespaceURI,
java.lang.String aLocalName)
Return the string value of the fully-qualified attribute.
|
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element aParent,
java.lang.String aName)
Perform a depth-first traversal of the parent element, and return the
first child element with a matching tag name.
|
static java.lang.String |
getElementNodeValue(org.w3c.dom.Element aNode)
Return a concatenated string of the text node children of the
given element node.
|
static org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Element aNode)
Return the first child element node of the given element node.
|
static org.w3c.dom.Element |
getNamedChildElement(org.w3c.dom.Element aNode,
java.lang.String aElemName)
Return the first child element node with a matching unqualified name.
|
static org.w3c.dom.Element |
getNamedChildElement(org.w3c.dom.Element aNode,
java.lang.String aNamespaceURI,
java.lang.String aLocalName)
Return the first child element node with a matching qualified name.
|
static java.util.List |
getNamedChildElements(org.w3c.dom.Element aNode,
java.lang.String aElemName)
Return all child element nodes with a matching unqualified name.
|
static java.util.List |
getNamedChildElements(org.w3c.dom.Element aNode,
java.lang.String aNamespaceURI,
java.lang.String aLocalName)
Return all child element nodes with a matching qualified name.
|
static org.w3c.dom.Element |
getNamedSiblingElement(org.w3c.dom.Element aNode,
java.lang.String aElemName)
Return the first sibling element node with a matching unqualified name.
|
static org.w3c.dom.Element |
getNamedSiblingElement(org.w3c.dom.Element aNode,
java.lang.String aNamespaceURI,
java.lang.String aLocalName)
Return the first sibling element node with a matching qualified name.
|
static org.w3c.dom.Element |
getNextSiblingElement(org.w3c.dom.Element aNode)
Return the immediate sibling element node of the given element node.
|
static javax.xml.namespace.QName |
getTypeQName(org.w3c.dom.Element aNode)
Return the resolved qualified name of the type referred to by the
'xsi:type' attribute of the given element node.
|
static boolean |
isNil(org.w3c.dom.Element aNode)
Return the boolean value of the named attribute.
|
static java.lang.String |
makeCloseTag(java.lang.String aType)
Makes a closing XML tag String based on the input.
|
static java.lang.String |
makeTag(java.lang.String aType,
java.util.Map<java.lang.String,java.lang.String> aAttrMap,
boolean aSelfClosing)
Makes an XML tag String based on the input.
|
static void |
removeElements(java.lang.StringBuilder aXMLBuffer,
java.lang.String aTypeRegex,
boolean aIsPrefix,
boolean aIgnoreCase)
Removes all elements from the XML String that have types matching the regex in the first argument.
|
static void |
removeElementsByNSPrefix(java.lang.StringBuilder aXMLBuffer,
java.lang.String aNsPrefix,
boolean aIgnoreCase)
Removes all elements from the XML string that have a namespace prefix matching the regex in the first argument.
|
static java.lang.String |
resolveNamespaceURI(org.w3c.dom.Element aNode,
java.lang.String aPrefix)
Return the namespace URI associated with the given prefix.
|
static java.lang.String |
resolveNSPrefix(org.w3c.dom.Element aNode,
java.lang.String aNamespaceURI)
Return the prefix associated with the given namespace URI.
|
static javax.xml.namespace.QName |
resolveQNameRef(org.w3c.dom.Element aNode,
java.lang.String aRefVal)
Return the resolved qualified name of the specified value,
which may contain a prefix that refers to a namespace mapping
in one of the node's ancestors.
|
static void |
simpleAddElement(java.lang.StringBuffer xml,
java.lang.String tag,
long data)
Given a stringbuffer of xml data, append a new tag named
tag data of data.
|
static void |
simpleAddElement(java.lang.StringBuffer xml,
java.lang.String tag,
java.lang.String data)
Given a stringbuffer of xml data, append a new tag named
tag data of data.
|
static void |
simpleAddElement(java.lang.StringBuffer xml,
java.lang.String tag,
java.lang.StringBuffer data)
Given a stringbuffer of xml data, append a new tag named
tag data of data.
|
static void |
simpleAddElement(java.lang.StringBuilder xml,
java.lang.String tag,
long data)
Given a stringbuffer of xml data, append a new tag named
tag data of data.
|
static void |
simpleAddElement(java.lang.StringBuilder xml,
java.lang.String tag,
java.lang.String data)
Given a stringbuffer of xml data, append a new tag named
tag data of data.
|
static void |
simpleAddElement(java.lang.StringBuilder xml,
java.lang.String tag,
java.lang.StringBuilder data)
Given a stringbuilder of xml data, append a new tag named
tag data of data.
|
static void |
simpleEmbedElements(java.lang.StringBuffer xml,
java.lang.String tag,
java.lang.String data)
Given a stringbuffer of xml data, append a new tag named tag data of data.
|
static void |
simpleEmbedElements(java.lang.StringBuffer xml,
java.lang.String tag,
java.lang.StringBuffer data)
Given a stringbuffer of xml data, append a new tag named
tag data of data.
|
static void |
simpleEmbedElements(java.lang.StringBuilder xml,
java.lang.String tag,
java.lang.String data)
Given a StringBuilder of xml data, append a new tag named tag data of data.
|
static void |
simpleEmbedElements(java.lang.StringBuilder xml,
java.lang.String tag,
java.lang.StringBuilder data)
Given a stringbuffer of xml data, append a new tag named
tag data of data.
|
static java.lang.String |
simpleStripHeader(java.lang.String xml)
Remove the XML header.
|
static java.lang.String |
simpleStripRoot(java.lang.String xml)
Strips root element from a string of xml.
|
public static final java.lang.String COPYRIGHT
public static final java.lang.String VERSION
public static java.lang.String resolveNamespaceURI(org.w3c.dom.Element aNode, java.lang.String aPrefix)
aNode
- the element node that the search will start fromaPrefix
- the prefix shortcut for the namespace URIpublic static java.lang.String resolveNSPrefix(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI)
aNode
- the element node that the search will start fromaNamespaceURI
- the namespace URI for the prefixpublic static javax.xml.namespace.QName resolveQNameRef(org.w3c.dom.Element aNode, java.lang.String aRefVal)
aNode
- the element node that the search will start fromaRefVal
- the value to be resolvedpublic static javax.xml.namespace.QName getTypeQName(org.w3c.dom.Element aNode)
aNode
- the element node that may contain
the 'xsi:type' attributepublic static java.lang.String getAttributeValue(org.w3c.dom.Element aNode, java.lang.String aAttrName)
aNode
- the element that contains the attributeaAttrName
- the unqualified attribute namepublic static boolean isNil(org.w3c.dom.Element aNode)
aNode
- the element that contains the attributepublic static java.lang.String getAttributeValue(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
aNode
- the element node that contains the attributeaNamespaceURI
- the namespace qualifier of the attribute nameaLocalName
- the local part of the attribute namepublic static java.lang.String getElementNodeValue(org.w3c.dom.Element aNode)
aNode
- the element nodepublic static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element aNode)
aNode
- the parent element nodepublic static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Element aNode)
aNode
- the element nodepublic static org.w3c.dom.Element getNamedChildElement(org.w3c.dom.Element aNode, java.lang.String aElemName)
aNode
- the parent element nodeaElemName
- the unqualified child element namepublic static org.w3c.dom.Element getNamedChildElement(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
aNode
- the parent element nodeaNamespaceURI
- the namespace qualifier of the child element nameaLocalName
- the local part of the child element namepublic static org.w3c.dom.Element getNamedSiblingElement(org.w3c.dom.Element aNode, java.lang.String aElemName)
aNode
- the starting element nodeaElemName
- the unqualified sibling element namepublic static org.w3c.dom.Element getNamedSiblingElement(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
aNode
- the starting element nodeaNamespaceURI
- the namespace qualifier of the sibling element nameaLocalName
- the local part of the sibling element namepublic static java.util.List getNamedChildElements(org.w3c.dom.Element aNode, java.lang.String aElemName)
aNode
- the parent element nodeaElemName
- the unqualified child element namepublic static java.util.List getNamedChildElements(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
aNode
- the parent element nodeaNamespaceURI
- the namespace qualifier of the child element nameaLocalName
- the local part of the child element namepublic static java.util.List getAllAttributes(org.w3c.dom.Element aNode)
aNode
- the element nodepublic static java.util.List getAllChildElements(org.w3c.dom.Element aNode)
aNode
- the parent element nodepublic static org.w3c.dom.Element getChildElement(org.w3c.dom.Element aParent, java.lang.String aName)
aParent
- the parent element nodeaName
- the element tag name to search forpublic static java.lang.String encodeString(java.lang.String in)
in
- string to encodepublic static java.lang.StringBuffer encode(java.lang.String string)
string
- to encodepublic static java.lang.StringBuffer encode(java.lang.StringBuffer in)
in
- buffer to encodepublic static java.lang.StringBuilder encode(java.lang.StringBuilder in)
in
- buffer to encodepublic static void simpleAddElement(java.lang.StringBuffer xml, java.lang.String tag, java.lang.StringBuffer data)
Data will be encoded.
xml
- tag
- data
- public static void simpleAddElement(java.lang.StringBuilder xml, java.lang.String tag, java.lang.StringBuilder data)
Data will be encoded.
xml
- tag
- data
- public static void simpleAddElement(java.lang.StringBuffer xml, java.lang.String tag, java.lang.String data)
Data will be encoded.
xml
- tag
- data
- public static void simpleAddElement(java.lang.StringBuilder xml, java.lang.String tag, java.lang.String data)
Data will be encoded.
xml
- tag
- data
- public static void simpleAddElement(java.lang.StringBuffer xml, java.lang.String tag, long data)
xml
- tag
- data
- public static void simpleAddElement(java.lang.StringBuilder xml, java.lang.String tag, long data)
xml
- tag
- data
- public static void simpleEmbedElements(java.lang.StringBuffer xml, java.lang.String tag, java.lang.StringBuffer data)
Data will *not* be encoded.
xml
- tag
- data
- public static void simpleEmbedElements(java.lang.StringBuilder xml, java.lang.String tag, java.lang.StringBuilder data)
Data will *not* be encoded.
xml
- tag
- data
- public static void simpleEmbedElements(java.lang.StringBuffer xml, java.lang.String tag, java.lang.String data)
Data will *not* be encoded.
xml
- tag
- data
- public static void simpleEmbedElements(java.lang.StringBuilder xml, java.lang.String tag, java.lang.String data)
Data will *not* be encoded.
xml
- tag
- data
- public static java.lang.String simpleStripHeader(java.lang.String xml)
Useful if this XML is to be encapsulated by other tags...
xml
- public static java.lang.String simpleStripRoot(java.lang.String xml)
ex: in:out:
xml
- XML to strippublic static void removeElementsByNSPrefix(java.lang.StringBuilder aXMLBuffer, java.lang.String aNsPrefix, boolean aIgnoreCase)
aXMLBuffer
- a StringBuilder containing XML data to processaNsPrefix
- a namespace prefixaIgnoreCase
- enables case-insensitivty for the regular expression.public static void removeElements(java.lang.StringBuilder aXMLBuffer, java.lang.String aTypeRegex, boolean aIsPrefix, boolean aIgnoreCase)
aXMLBuffer
- a StringBuilder containing XML data to processaTypeRegex
- a java-formatted regular expression for finding elementsaIsPrefix
- enables using the regex as a prefix for element types intead of exact.aIgnoreCase
- enables case-insensitive mode for regular expressionpublic static void collectElements(java.lang.StringBuilder aXMLBuffer, java.lang.String aTypeRegex, boolean aIsPrefix, boolean aIgnoreCase, boolean aRemove, java.util.Collection aCollection)
aXMLBuffer
- a StringBuilder containing XML data to processaTypeRegex
- a java-formatted regular expression for finding elementsaIsPrefix
- enables using the regex as a prefix for element types instead of exact.aIgnoreCase
- enables case-insensitive mode for regular expressionaRemove
- removes elements upon discoveryaCollection
- a java collection for placing String representations of discovered elementspublic static java.util.Map<java.lang.String,java.lang.String> getAttributesFromTag(java.lang.String aTag) throws java.lang.IllegalArgumentException
aTag
- the text rep of a tagjava.lang.IllegalArgumentException
public static java.util.Map<java.lang.String,java.lang.String> getAttributesFromTag(java.lang.String aTag, boolean isHTML) throws java.lang.IllegalArgumentException
aTag
- the text rep of a tagisHTML
- enables or disables forcing lowercase-key entries in the mapjava.lang.IllegalArgumentException
public static java.lang.String makeCloseTag(java.lang.String aType)
aType
- the type of tagpublic static java.lang.String makeTag(java.lang.String aType, java.util.Map<java.lang.String,java.lang.String> aAttrMap, boolean aSelfClosing)
aType
- the type of tagaAttrMap
- a map of attributes to includeaSelfClosing
- enables the tag to close itselfpublic static org.w3c.dom.Node findNode(org.w3c.dom.Element aElement, java.lang.String aNodeType, java.lang.String aAttrKey, java.lang.String aAttrValue)
aNodeType
- - the type of node to findaAttrKey
- - the key of an attribute to search foraAttrValue
- - the value of an attribute to search foraElement
- - an element to searchpublic static org.w3c.dom.Node findNode(org.w3c.dom.Element aElement, java.lang.String aNodeType, java.util.Map<java.lang.String,java.lang.String> aAttributeMap)
aNodeType
- - the type of node to search foraAttributeMap
- - a subset of the attributes for the Node to be foundaElement
- the element with children to be searchedCopyright © 2018 Pegasystems Inc. All Rights Reserved.