public class XMLUtils extends Object
Constructor and Description |
---|
XMLUtils() |
Modifier and Type | Method and Description |
---|---|
static SAXSource |
createSAXSource(InputSource source)
Creates a SAXSource instance based on the incoming InputSource, which
later on can be safely used by JAXB unmarshalling.
|
static Set |
decodeAttributeSet(Set set) |
static Set |
encodeAttributeSet(Set set,
Debug debug) |
static String |
escapeSpecialCharacters(String text)
Removes invalid XML characters from the input text and then replaces XML special character
& ,
< , > , " , ' with corresponding entity references. |
String |
getATTR_VALUE_PAIR_NODE() |
static Set<String> |
getAttributeValuePair(Node node)
Method to get Values within AttributeValuePair as a java.util.Set
|
static Set<String> |
getAttributeValuePair(Node node,
boolean unescape)
Method to get Values within AttributeValuePair as a java.util.Set
If
|
static Node |
getChildNode(Node parentNode,
String childName) |
static Set |
getChildNodes(Node parentNode,
String childName) |
static String |
getChildrenValue(Element element)
Gets the children value of an element.
|
static List |
getElementsByTagNameNS1(Element element,
String nsName,
String tagName)
This method searches children of Element element for element with tagName
and namespaceURI nsName.
|
static String |
getElementString(Element element)
Gets the value of an element.
|
static String |
getElementValue(Element element)
Gets the value of an element.
|
static Node |
getNamedChildNode(Node parentNode,
String childNodeName,
String attrName,
String attrValue)
Returns a child node that has the given node name and give attribute name
and value.
|
static String |
getNodeAttributeValue(Node node,
String attrName) |
static String |
getNodeAttributeValueNS(Node node,
String namespaceURI,
String attrName)
Gets attribute value of a node.
|
static Node |
getRootNode(Document doc,
String nodeName) |
static DocumentBuilder |
getSafeDocumentBuilder(boolean validating)
Provides a secure DocumentBuilder implementation, which is protected against
different types of entity expansion attacks and makes sure that only locally
available DTDs can be referenced within the XML document.
|
static SAXParser |
getSafeSAXParser(boolean validating)
Provides a secure SAXParser instance, which is protected against different
types of entity expension, DoS attacks and makes sure that only locally
available DTDs can be referenced within the XML document.
|
static TransformerFactory |
getTransformerFactory()
Provides a cached
TransformerFactory instance for the current thread. |
static String |
getValueOfValueNode(Node n)
Method to get the value of "Value" node
|
static String |
getValueOfValueNode(Node n,
boolean unescape)
Method to get the value of "Value" node
If
|
static String |
getValueOfValueNodeNoTrim(Node n)
Method to get the value of "Value" node
|
static String |
getValueOfValueNodeNoTrim(Node n,
boolean unescape)
Method to get the value of "Value" node
If
|
static Document |
getXMLDocument(InputStream in) |
static boolean |
hasElementChild(Node node)
Checks if a node has a child of ELEMENT type.
|
static boolean |
isValidating() |
static Document |
newDocument()
Obtains a new instance of a DOM Document object
|
static Set |
parseAttributesTag(Node n)
This method parse an Attributes tag, DTD for Attribute is as follows.
|
static Map<String,Set<String>> |
parseAttributeValuePairTags(Node parentNode) |
static String |
print(Node node)
Print a Node tree recursively using UTF-8 encoding.
|
static String |
print(Node node,
String encoding)
Prints a Node tree recursively.
|
static String |
printAttributeValue(Element node,
String prefix)
Print SAML Attribute Element and replace its prefix with the input
prefix.
|
static String |
removeInvalidXMLChars(String text)
Remove invalid XML characters from a string.
|
static String |
removeNullCharAtEnd(String st) |
static Document |
toDOMDocument(InputStream is,
Debug debug)
Converts the XML document from an input stream to DOM Document format.
|
static Document |
toDOMDocument(String xmlString,
Debug debug)
Converts the XML document from a String format to DOM Document format.
|
static String |
unescapeSpecialCharacters(String text)
Returns unescape special character text.
|
public String getATTR_VALUE_PAIR_NODE()
public static boolean isValidating()
public static Document toDOMDocument(String xmlString, Debug debug)
xmlString
- is the XML document in a String formatdebug
- is the debug object used for logging debug infopublic static Document toDOMDocument(InputStream is, Debug debug)
is
- is the InputStream that contains XML documentpublic static Set parseAttributesTag(Node n)
< !-- This DTD defines the DPro Attribute tag. Unique Declaration name for DOCTYPE tag: "Directory Pro 5.0 Attributes DTD" --> < !ELEMENT Attributes (Attribute)+> < !ELEMENT Attribute EMPTY> < !ATTLIST Attribute name NMTOKEN #REQUIRED >
n
- Nodepublic static Map<String,Set<String>> parseAttributeValuePairTags(Node parentNode)
parentNode
- is the element tag that contains all the AttirbuteValuePair
tags as childrenpublic static Document newDocument() throws ParserConfigurationException
Exception
- if an error occurs while constructing a new documentParserConfigurationException
public static Document getXMLDocument(InputStream in) throws Exception
Exception
public static boolean hasElementChild(Node node)
node
- a nodepublic static Node getNamedChildNode(Node parentNode, String childNodeName, String attrName, String attrValue)
public static String getElementValue(Element element)
element
- a DOM tree element.public static String getChildrenValue(Element element)
element
- a DOM tree element.public static String getElementString(Element element)
element
- a DOM tree element.public static String getNodeAttributeValueNS(Node node, String namespaceURI, String attrName)
node
- a nodenamespaceURI
- attribute namespace URIattrName
- attribute namepublic static Set<String> getAttributeValuePair(Node node)
public static Set<String> getAttributeValuePair(Node node, boolean unescape)
public static String getValueOfValueNode(Node n)
public static String getValueOfValueNode(Node n, boolean unescape)
public static String getValueOfValueNodeNoTrim(Node n)
public static String getValueOfValueNodeNoTrim(Node n, boolean unescape)
public static List getElementsByTagNameNS1(Element element, String nsName, String tagName)
element
- The root elementnsName
- NamespaceURItagName
- A String representing the name of the tag to be searched for.public static String printAttributeValue(Element node, String prefix)
node
- A DOM tree Nodeprefix
- A String representing the new prefixpublic static String print(Node node)
node
- A DOM tree Nodepublic static String print(Node node, String encoding)
node
- A DOM tree Nodeencoding
- character encodingpublic static String unescapeSpecialCharacters(String text)
text
- String to be unescaped.public static String escapeSpecialCharacters(String text)
&
,
<
, >
, "
, '
with corresponding entity references.text
- The input that needs to be escaped. May be null.public static String removeInvalidXMLChars(String text)
text
- the text to cleanse.public static DocumentBuilder getSafeDocumentBuilder(boolean validating) throws ParserConfigurationException
validating
- Whether the returned DocumentBuilder should validate input.ParserConfigurationException
- In case xerces does not support one
of the required features.public static SAXParser getSafeSAXParser(boolean validating) throws ParserConfigurationException, SAXException
validating
- Whether the returned DocumentBuilder should validate input.ParserConfigurationException
- In case Xerces does not support one of
the required features.SAXException
- In case Xerces does not support one of the required
features.public static TransformerFactory getTransformerFactory()
TransformerFactory
instance for the current thread.TransformerFactory
instance.public static SAXSource createSAXSource(InputSource source) throws JAXBException
source
- The InputSource to be unmarshalled by JAXBJAXBException
- In case an error occurs while creating the SAXSourceCopyright © 2010–2025 Open Identity Platform Community. All rights reserved.