public final class XmlUtils
extends java.lang.Object
| 构造器和说明 |
|---|
XmlUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static org.w3c.dom.Element |
appendCDATAElement(org.w3c.dom.Element parent,
java.lang.String tagName,
java.lang.String value)
Appends the CDATA element to the parent element.
|
static void |
appendElement(org.w3c.dom.Element parent,
org.w3c.dom.Element child)
Appends another element as a child element.
|
static org.w3c.dom.Element |
appendElement(org.w3c.dom.Element parent,
java.lang.String tagName)
Appends the child element to the parent element.
|
static org.w3c.dom.Element |
appendElement(org.w3c.dom.Element parent,
java.lang.String tagName,
java.lang.String value)
Appends the child element as well as value to the parent element.
|
static java.lang.String |
childNodeToString(org.w3c.dom.Node node)
Converts the Node/Element instance to XML payload.
|
static org.w3c.dom.Element |
createRootElement(java.lang.String tagName)
Creates a root element as well as a new document with specific tag name.
|
static java.lang.String |
encodeXml(java.lang.String payload)
Encode the XML payload to legality character.
|
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element parent,
java.lang.String tagName)
Gets the immediately child element from the parent element.
|
static java.util.List<org.w3c.dom.Element> |
getChildElements(org.w3c.dom.Element parent,
java.lang.String tagName)
Gets the immediately child elements list from the parent element.
|
static org.w3c.dom.Document |
getDocument(java.io.File file)
Parses the content of the given XML file as an XML document.
|
static org.w3c.dom.Document |
getDocument(java.io.InputStream in)
Parses the content of the given stream as an XML document.
|
static org.w3c.dom.Element |
getElement(org.w3c.dom.Element parent,
java.lang.String tagName)
Gets the immediately descendant element from the parent element.
|
static java.util.List<org.w3c.dom.Element> |
getElements(org.w3c.dom.Element parent,
java.lang.String tagName)
Gets the descendant elements list from the parent element.
|
static java.lang.String |
getElementValue(org.w3c.dom.Element element)
Gets the text value of current element.
|
static java.lang.String |
getElementValue(org.w3c.dom.Element parent,
java.lang.String tagName)
Gets the value of the child element by tag name under the given parent
element.
|
static org.w3c.dom.Element |
getRootElementFromFile(java.io.File file)
Gets the root element from given XML file.
|
static org.w3c.dom.Element |
getRootElementFromStream(java.io.InputStream in)
Gets the root element from input stream.
|
static org.w3c.dom.Element |
getRootElementFromString(java.lang.String payload)
Gets the root element from the given XML payload.
|
static org.w3c.dom.Document |
newDocument()
Creates a new document instance.
|
static java.lang.String |
nodeToString(org.w3c.dom.Node node)
Converts the Node/Document/Element instance to XML payload.
|
static void |
saveToXml(org.w3c.dom.Node doc,
java.io.File file)
Saves the node/document/element as XML file.
|
static void |
setNamespace(org.w3c.dom.Element element,
java.lang.String namespace,
java.lang.String schemaLocation)
Sets the namespace to specific element.
|
static void |
validateXml(org.w3c.dom.Node doc,
java.io.File schemaFile)
Validates the element tree context via given XML schema file.
|
static void |
validateXml(org.w3c.dom.Node doc,
java.io.InputStream schemaStream)
Validates the element tree context via given XML schema file.
|
static java.lang.String |
xmlToHtml(java.lang.String payload,
java.io.File xsltFile)
Transforms the XML content to XHTML/HTML format string with the XSL.
|
static java.lang.String |
xmlToString(java.io.File file)
Converts the an XML file to XML payload.
|
static java.lang.String |
xmlToString(java.io.InputStream in)
Converts the an XML file input stream to XML payload.
|
public static org.w3c.dom.Document newDocument()
throws AlipayApiException
AlipayApiException - problem creating a new documentpublic static org.w3c.dom.Document getDocument(java.io.File file)
throws AlipayApiException
file - the XML file instanceAlipayApiException - problem parsing the XML filepublic static org.w3c.dom.Document getDocument(java.io.InputStream in)
throws AlipayApiException
in - the XML file input streamAlipayApiException - problem parsing the XML input streampublic static org.w3c.dom.Element createRootElement(java.lang.String tagName)
throws AlipayApiException
tagName - the name of the root elementAlipayApiException - problem generating a new documentpublic static org.w3c.dom.Element getRootElementFromStream(java.io.InputStream in)
throws AlipayApiException
in - the XML file input streamAlipayApiException - problem parsing the XML file input streampublic static org.w3c.dom.Element getRootElementFromFile(java.io.File file)
throws AlipayApiException
file - the name of the XML fileAlipayApiException - problem parsing the XML filepublic static org.w3c.dom.Element getRootElementFromString(java.lang.String payload)
throws AlipayApiException
payload - the XML payload representing the XML file.AlipayApiException - problem parsing the XML payloadpublic static java.util.List<org.w3c.dom.Element> getElements(org.w3c.dom.Element parent,
java.lang.String tagName)
parent - the parent element in the element treetagName - the specified tag namepublic static org.w3c.dom.Element getElement(org.w3c.dom.Element parent,
java.lang.String tagName)
parent - the parent element in the element treetagName - the specified tag name.public static java.util.List<org.w3c.dom.Element> getChildElements(org.w3c.dom.Element parent,
java.lang.String tagName)
parent - the parent element in the element treetagName - the specified tag namepublic static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parent,
java.lang.String tagName)
parent - the parent element in the element treetagName - the specified tag namepublic static java.lang.String getElementValue(org.w3c.dom.Element parent,
java.lang.String tagName)
parent - the parent elementtagName - the tag name of the child elementpublic static java.lang.String getElementValue(org.w3c.dom.Element element)
element - the current elementpublic static org.w3c.dom.Element appendElement(org.w3c.dom.Element parent,
java.lang.String tagName)
parent - the parent elementtagName - the child element namepublic static org.w3c.dom.Element appendElement(org.w3c.dom.Element parent,
java.lang.String tagName,
java.lang.String value)
parent - the parent elementtagName - the child element namevalue - the child element valuepublic static void appendElement(org.w3c.dom.Element parent,
org.w3c.dom.Element child)
parent - the parent elementchild - the child element to appendpublic static org.w3c.dom.Element appendCDATAElement(org.w3c.dom.Element parent,
java.lang.String tagName,
java.lang.String value)
parent - the parent elementtagName - the CDATA element namevalue - the CDATA element valuepublic static java.lang.String childNodeToString(org.w3c.dom.Node node)
throws AlipayApiException
node - the node/element instance to convertAlipayApiException - problem converting XML to stringpublic static java.lang.String nodeToString(org.w3c.dom.Node node)
throws AlipayApiException
node - the node/document/element instance to convertAlipayApiException - problem converting XML to stringpublic static java.lang.String xmlToString(java.io.File file)
throws AlipayApiException
file - the XML file instanceAlipayApiException - problem transforming XML to stringpublic static java.lang.String xmlToString(java.io.InputStream in)
throws AlipayApiException
in - the XML file input streamAlipayApiException - problem transforming XML to stringpublic static void saveToXml(org.w3c.dom.Node doc,
java.io.File file)
throws AlipayApiException
doc - the XML node/document/element to savefile - the XML file to saveAlipayApiException - problem persisting XML filepublic static void validateXml(org.w3c.dom.Node doc,
java.io.File schemaFile)
throws AlipayApiException
doc - the XML document to validateschemaFile - the XML schema file instanceAlipayApiException - error occurs if the schema file not existspublic static void validateXml(org.w3c.dom.Node doc,
java.io.InputStream schemaStream)
throws AlipayApiException
doc - the XML document to validateschemaStream - the XML schema file input streamAlipayApiException - error occurs if validation failpublic static java.lang.String xmlToHtml(java.lang.String payload,
java.io.File xsltFile)
throws AlipayApiException
payload - the XML payload to convertxsltFile - the XML stylesheet fileAlipayApiException - problem converting XML to HTMLpublic static void setNamespace(org.w3c.dom.Element element,
java.lang.String namespace,
java.lang.String schemaLocation)
element - the element to setnamespace - the namespace to setschemaLocation - the XML schema file location URIpublic static java.lang.String encodeXml(java.lang.String payload)
throws AlipayApiException
payload - the XML payload to encodeAlipayApiException - problem encoding the XML payloadCopyright © 2018. All Rights Reserved.