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 Element |
getChildElement(Element parent,
String tagName)
Gets the immediately child element from the parent element.
|
static List<Element> |
getChildElements(Element parent,
String tagName)
Gets the immediately child elements list from the parent element.
|
static Document |
getDocument(File file)
Parses the content of the given XML file as an XML document.
|
static Document |
getDocument(InputStream in)
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 file)
Gets the root element from given XML file.
|
static Element |
getRootElementFromStream(InputStream in)
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 |
setNamespace(Element element,
String namespace,
String schemaLocation)
Sets the namespace to specific element.
|
static void |
validateXml(Node doc,
File schemaFile)
Validates the element tree context via given XML schema file.
|
static void |
validateXml(Node doc,
InputStream schemaStream)
Validates the element tree context via 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 AlipayApiException
AlipayApiException - the alipay api exceptionpublic static Document getDocument(File file) throws AlipayApiException
file - the XML file instanceAlipayApiException - the alipay api exceptionpublic static Document getDocument(InputStream in) throws AlipayApiException
in - the XML file input streamAlipayApiException - the alipay api exceptionpublic static Element createRootElement(String tagName) throws AlipayApiException
tagName - the name of the root elementAlipayApiException - the alipay api exceptionpublic static Element getRootElementFromStream(InputStream in) throws AlipayApiException
in - the XML file input streamAlipayApiException - the alipay api exceptionpublic static Element getRootElementFromFile(File file) throws AlipayApiException
file - the fileAlipayApiException - the alipay api exceptionpublic static Element getRootElementFromString(String payload) throws AlipayApiException
payload - the XML payload representing the XML file.AlipayApiException - the alipay api exceptionpublic 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 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 getElementValue(Element element)
element - the 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 AlipayApiException
node - the node/element instance to convertAlipayApiException - the alipay api exceptionpublic static String nodeToString(Node node) throws AlipayApiException
node - the node/document/element instance to convertAlipayApiException - the alipay api exceptionpublic static String xmlToString(File file) throws AlipayApiException
file - the XML file instanceAlipayApiException - the alipay api exceptionpublic static String xmlToString(InputStream in) throws AlipayApiException
in - the XML file input streamAlipayApiException - the alipay api exceptionpublic static void saveToXml(Node doc, File file) throws AlipayApiException
doc - the XML node/document/element to savefile - the XML file to saveAlipayApiException - the alipay api exceptionpublic static void validateXml(Node doc, File schemaFile) throws AlipayApiException
doc - the XML document to validateschemaFile - the XML schema file instanceAlipayApiException - the alipay api exceptionpublic static void validateXml(Node doc, InputStream schemaStream) throws AlipayApiException
doc - the XML document to validateschemaStream - the XML schema file input streamAlipayApiException - the alipay api exceptionpublic static String xmlToHtml(String payload, File xsltFile) throws AlipayApiException
payload - the XML payload to convertxsltFile - the XML stylesheet fileAlipayApiException - the alipay api exceptionpublic 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 AlipayApiException
payload - the XML payload to encodeAlipayApiException - the alipay api exceptionCopyright © 2018. All rights reserved.