public final class XmlUtils extends Object
| Constructor and Description |
|---|
XmlUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Element |
appendCDATAElement(Element parent,
String tagName,
String value)
Appends the CDATA element to the parent element.
|
static void |
appendElement(Element parent,
Element child)
Appends another element as a child element.
|
static Element |
appendElement(Element parent,
String tagName)
Appends the child element to the parent element.
|
static Element |
appendElement(Element parent,
String tagName,
String value)
Appends the child element as well as value to the parent element.
|
static String |
childNodeToString(Node node)
Converts the Node/Element instance to XML payload.
|
static Element |
createRootElement(String tagName)
Creates a root element as well as a new document with specific tag name.
|
static String |
encodeXml(String payload)
Encode the XML payload to legality character.
|
static String |
escapeXml(String payload) |
static String |
getAttributeValue(Element current,
String attrName)
Gets the specific attribute's value form current element.
|
static Element |
getChildElement(Element parent,
String tagName)
Gets the immediately child element from the parent element.
|
static List<Element> |
getChildElements(Element parent)
Gets the immediately child elements list from the parent element.
|
static List<Element> |
getChildElements(Element parent,
String tagName)
Gets the immediately child elements list from the parent element.
|
static String |
getChildElementValue(Element parent,
String tagName)
Gets the value of the immediately child element by tag name under the given parent
element.
|
static Document |
getDocument(File file)
Parses the content of the given XML file as an XML document.
|
static Document |
getDocument(InputSource xml,
InputStream xsd)
Parses the content of the given stream as an XML document.
|
static Element |
getElement(Element parent,
String tagName)
Gets the immediately descendant element from the parent element.
|
static List<Element> |
getElements(Element parent,
String tagName)
Gets the descendant elements list from the parent element.
|
static String |
getElementValue(Element element)
Gets the text value of current element.
|
static String |
getElementValue(Element parent,
String tagName)
Gets the value of the child element by tag name under the given parent
element.
|
static Element |
getRootElementFromFile(File xml)
Gets the root element from given XML file.
|
static Element |
getRootElementFromStream(InputStream xml)
Gets the root element from input stream.
|
static Element |
getRootElementFromStream(InputStream xml,
InputStream xsd)
Gets the root element from input stream.
|
static Element |
getRootElementFromString(String payload)
Gets the root element from the given XML payload.
|
static Document |
newDocument()
Creates a new document instance.
|
static String |
nodeToString(Node node)
Converts the Node/Document/Element instance to XML payload.
|
static void |
saveToXml(Node doc,
File file)
Saves the node/document/element as XML file.
|
static void |
saveToXml(Node doc,
File file,
String charset)
Saves the node/document/element as XML file.
|
static void |
setNamespace(Element element,
String namespace,
String schemaLocation)
Sets the namespace to specific element.
|
static void |
validateXml(InputStream xml,
InputStream xsd)
Validates the XML file via the given XML schema file.
|
static void |
validateXml(Node root,
InputStream xsd)
Validates the XML file via the given XML schema file.
|
static String |
xmlToHtml(String payload,
File xsltFile)
Transforms the XML content to XHTML/HTML format string with the XSL.
|
static String |
xmlToString(File file)
Converts the an XML file to XML payload.
|
static String |
xmlToString(InputStream in)
Converts the an XML file input stream to XML payload.
|
public static Document newDocument() throws ApiException
ApiException - problem creating a new documentpublic static Document getDocument(File file) throws ApiException
file - the XML file instanceApiException - problem parsing the XML filepublic static Document getDocument(InputSource xml, InputStream xsd) throws ApiException
xml - the XML file input streamApiException - problem parsing the XML input streampublic static Element createRootElement(String tagName) throws ApiException
tagName - the name of the root elementApiException - problem generating a new documentpublic static Element getRootElementFromStream(InputStream xml) throws ApiException
xml - the XML file input streamApiException - problem parsing the XML file input streampublic static Element getRootElementFromStream(InputStream xml, InputStream xsd) throws ApiException
xml - the XML file input streamApiException - problem parsing the XML file input streampublic static Element getRootElementFromFile(File xml) throws ApiException
xml - the name of the XML fileApiException - problem parsing the XML filepublic static Element getRootElementFromString(String payload) throws ApiException
payload - the XML payload representing the XML file.ApiException - problem parsing the XML payloadpublic static List<Element> getElements(Element parent, String tagName)
parent - the parent element in the element treetagName - the specified tag namepublic static Element getElement(Element parent, String tagName)
parent - the parent element in the element treetagName - the specified tag name.public static List<Element> getChildElements(Element parent, String tagName)
parent - the parent element in the element treetagName - the specified tag namepublic static List<Element> getChildElements(Element parent)
parent - the parent element in the element treepublic static Element getChildElement(Element parent, String tagName)
parent - the parent element in the element treetagName - the specified tag namepublic static String getElementValue(Element parent, String tagName)
parent - the parent elementtagName - the tag name of the child elementpublic static String getChildElementValue(Element parent, String tagName)
parent - the parent elementtagName - the tag name of the child elementpublic static String getElementValue(Element element)
parent - the current elementpublic static String getAttributeValue(Element current, String attrName)
current - current elementattrName - attribute name in current elementpublic static Element appendElement(Element parent, String tagName)
parent - the parent elementtagName - the child element namepublic static Element appendElement(Element parent, String tagName, String value)
parent - the parent elementtagName - the child element namevalue - the child element valuepublic static void appendElement(Element parent, Element child)
parent - the parent elementchild - the child element to appendpublic static Element appendCDATAElement(Element parent, String tagName, String value)
parent - the parent elementtagName - the CDATA element namevalue - the CDATA element valuepublic static String childNodeToString(Node node) throws ApiException
node - the node/element instance to convertApiException - problem converting XML to stringpublic static String nodeToString(Node node) throws ApiException
node - the node/document/element instance to convertApiException - problem converting XML to stringpublic static String xmlToString(File file) throws ApiException
file - the XML file instanceApiException - problem transforming XML to stringpublic static String xmlToString(InputStream in) throws ApiException
in - the XML file input streamApiException - problem transforming XML to stringpublic static void saveToXml(Node doc, File file) throws ApiException
doc - the XML node/document/element to savefile - the XML file to saveApiException - problem persisting XML filepublic static void saveToXml(Node doc, File file, String charset) throws ApiException
doc - the XML node/document/element to savefile - the XML file to savecharset - the string encoding charsetApiException - problem persisting XML filepublic static void validateXml(InputStream xml, InputStream xsd) throws ApiException
xml - the XML file to validatexsd - the XML schema fileApiException - error occurs if validation failpublic static void validateXml(Node root, InputStream xsd) throws ApiException
root - the root element of XMLxsd - the XML schema fileApiException - error occurs if validation failpublic static String xmlToHtml(String payload, File xsltFile) throws ApiException
payload - the XML payload to convertxsltFile - the XML stylesheet fileApiException - problem converting XML to HTMLpublic static void setNamespace(Element element, String namespace, String schemaLocation)
element - the element to setnamespace - the namespace to setschemaLocation - the XML schema file location URIpublic static String encodeXml(String payload) throws ApiException
payload - the XML payload to encodeApiException - problem encoding the XML payloadCopyright © 2021. All rights reserved.