public final class XMLUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Date |
asDate(XMLGregorianCalendar xgc)
Converts an XMLGregorianCalendar to an instance of java.util.Date.
|
static XMLGregorianCalendar |
asXMLGregorianCalendar(Date date)
Converts a java.util.Date into an instance of XMLGregorianCalendar.
|
static Document |
createDocument()
Create an empty DOM Document.
|
static Document |
createDocument(File file)
Create a DOM document from a file of XML.
|
static Document |
createDocument(InputStream inputStream)
Create a DOM document from an input stream of XML.
|
static Document |
createDocument(String xmlString)
Create a DOM document from a String of XML.
|
static Document |
createDocumentFromResource(String resourceName)
Creates a DOM document from a a resource of the specified name loaded
from the classpath.
|
static Element |
createElement(Document document,
String tagName,
String value)
Creates an element with a value.
|
static String |
getChildElementText(Element element,
String childTagName)
Gets text from a child element.
|
static String |
serialize(Document document)
Serialize a document to a flat (unformatted) string of XML.
|
static String |
serialize(Document document,
boolean pretty)
Serializes a document to a String.
|
public static Document createDocument() throws APIException
APIException
- if unable to create document.public static Element createElement(Document document, String tagName, String value)
document
- the parent documenttagName
- the element tag namevalue
- the valuepublic static String serialize(Document document, boolean pretty) throws APIException
document
- the documentpretty
- whether to pretty print. If false then the document is
serialized to a flat string but if true then formatting is
included.APIException
- if unable to serializepublic static String serialize(Document document)
document
- the DOM document.public static Document createDocument(String xmlString) throws APIException
xmlString
- a string of XMLAPIException
- if unable to parse the string.public static Document createDocument(InputStream inputStream) throws APIException
inputStream
- from which XML is to be read.APIException
- if unable to parse XML.public static Document createDocumentFromResource(String resourceName) throws APIException
resourceName
- the resource name.APIException
- if no resource with the given name could be found or
the XML within it could not be parsed.public static Document createDocument(File file) throws APIException
file
- containing XMLAPIException
- if unable to parse XML.public static String getChildElementText(Element element, String childTagName)
This is a convenience method to return the text from the first child element with a given tag name.
If there is no such child element then this will return a zero length String.
element
- the parent element.childTagName
- the child tagpublic static XMLGregorianCalendar asXMLGregorianCalendar(Date date)
date
- Instance of java.util.Date or a null referencepublic static Date asDate(XMLGregorianCalendar xgc)
xgc
- Instance of XMLGregorianCalendar or a null referenceCopyright © 2016 Push Technology Ltd. All Rights Reserved.