public class XMLUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static List<Object> |
convertContentToDocument(byte[] content)
Convert a byte[] array to a List of DOM objects.
|
static String |
convertDocumentToString(Document document)
Converts the passed
Document to a String. |
static Object |
escape(Object content)
Removes XML characters ('&', ''', '"', '<' and '>') from passed content.
|
static String |
getAttributeValue(Document parent,
String tagName,
String attributeName) |
static String |
getAttributeValue(Element parent,
String tagName,
String attributeName) |
static Element |
getElement(Document doc,
String tagName,
int index)
Return an Element given an XML document, tag name, and index.
|
static Element |
getFirstElement(Element parent,
String tagName) |
static int |
getSize(Document doc,
String tagName)
Return the number of person in an XML document.
|
static String |
getValue(Element e,
String tagName)
Given a person element, must get the element specified
by the tagName, then must traverse that Node to get the value.
|
static Element |
loadXML(InputStream xmlStream)
Passed xml string will be loaded if passed string is well formed xml.
|
static void |
printNodeTypes(NodeList rows)
For testing purpose, it print out Node list.
|
static String |
removeBOMForUTF8(String content)
Removes BOM characters for UTF-8 files.
|
static String |
removeNonAlphaNumericChars(String originalString)
Removes everything except letters and numbers from the provided String.
|
public static Element getElement(Document doc, String tagName, int index)
doc - XML docuemnttagName - a tag nameindex - a indexpublic static int getSize(Document doc, String tagName)
doc - XML documenttagName - a tag namepublic static String getValue(Element e, String tagName)
NOTE: Element is a subclass of Node
e - an ElementtagName - a tag namepublic static String getAttributeValue(Element parent, String tagName, String attributeName)
parent - an ElementtagName - a tag namepublic static String getAttributeValue(Document parent, String tagName, String attributeName)
parent - an DocumenttagName - a tag namepublic static void printNodeTypes(NodeList rows)
rows - a Nodelistpublic static String convertDocumentToString(Document document)
Document to a String.document - The Document to convert.Document.public static List<Object> convertContentToDocument(byte[] content) throws ParserConfigurationException, SAXException, IOException
content - All the XML nodes that will be converted to DOM.ParserConfigurationExceptionSAXExceptionIOExceptionpublic static String removeBOMForUTF8(String content)
content - Content of the file that might contain BOM.public static Object escape(Object content)
content - The content before escaping.public static Element loadXML(InputStream xmlStream)
xmlStream - xml as a streamCopyright (c) 2014-2021 All Rights Reserved by the RWS Group for and on behalf of its affiliates and subsidiaries