public class XmlUtils extends Object
构造器和说明 |
---|
XmlUtils() |
限定符和类型 | 方法和说明 |
---|---|
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 WXPayApiException
WXPayApiException
- problem creating a new documentpublic static Document getDocument(File file) throws WXPayApiException
file
- the XML file instanceWXPayApiException
- problem parsing the XML filepublic static Document getDocument(InputStream in) throws WXPayApiException
in
- the XML file input streamWXPayApiException
- problem parsing the XML input streampublic static Element createRootElement(String tagName) throws WXPayApiException
tagName
- the name of the root elementWXPayApiException
- problem generating a new documentpublic static Element getRootElementFromStream(InputStream in) throws WXPayApiException
in
- the XML file input streamWXPayApiException
- problem parsing the XML file input streampublic static Element getRootElementFromFile(File file) throws WXPayApiException
file
- the name of the XML fileWXPayApiException
- problem parsing the XML filepublic static Element getRootElementFromString(String payload) throws WXPayApiException
payload
- the XML payload representing the XML file.WXPayApiException
- 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 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 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 WXPayApiException
node
- the node/element instance to convertWXPayApiException
- problem converting XML to stringpublic static String nodeToString(Node node) throws WXPayApiException
node
- the node/document/element instance to convertWXPayApiException
- problem converting XML to stringpublic static String xmlToString(File file) throws WXPayApiException
file
- the XML file instanceWXPayApiException
- problem transforming XML to stringpublic static String xmlToString(InputStream in) throws WXPayApiException
in
- the XML file input streamWXPayApiException
- problem transforming XML to stringpublic static void saveToXml(Node doc, File file) throws WXPayApiException
doc
- the XML node/document/element to savefile
- the XML file to saveWXPayApiException
- problem persisting XML filepublic static void validateXml(Node doc, File schemaFile) throws WXPayApiException
doc
- the XML document to validateschemaFile
- the XML schema file instanceWXPayApiException
- error occurs if the schema file not existspublic static void validateXml(Node doc, InputStream schemaStream) throws WXPayApiException
doc
- the XML document to validateschemaStream
- the XML schema file input streamWXPayApiException
- error occurs if validation failpublic static String xmlToHtml(String payload, File xsltFile) throws WXPayApiException
payload
- the XML payload to convertxsltFile
- the XML stylesheet fileWXPayApiException
- 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 WXPayApiException
payload
- the XML payload to encodeWXPayApiException
- problem encoding the XML payloadCopyright © 2017. All rights reserved.