public class XmlUtils extends Object
| 构造器和说明 |
|---|
XmlUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
appendElement(org.dom4j.Element parent,
org.dom4j.Element child)
Appends another element as a child element.
|
static org.dom4j.Element |
appendElement(org.dom4j.Element parent,
String tagName)
Appends the child element to the parent element.
|
static org.dom4j.Element |
createRootElement(String tagName)
Creates a root element as well as a new document with specific tag name.
|
static String |
escapeXml(String payload) |
static String |
getAttributeValue(org.dom4j.Element current,
String attrName)
Gets the specific attribute's value form current element.
|
static org.dom4j.Element |
getChildElement(org.dom4j.Element parent,
String tagName)
Gets the immediately child element from the parent element.
|
static List<org.dom4j.Element> |
getChildElements(org.dom4j.Element parent,
String tagName)
Gets the immediately child elements list from the parent element.
|
static org.dom4j.Document |
getDocument(File file)
Parses the content of the given XML file as an XML document.
|
static org.dom4j.Document |
getDocument(InputSource xml)
Parses the content of the given XML file as an XML document.
|
static org.dom4j.Document |
getDocument(InputStream xml)
Parses the content of the given XML file as an XML document.
|
static org.dom4j.Element |
getElement(org.dom4j.Element parent,
String tagName)
Gets the immediately descendant element from the parent element.
|
static List<org.dom4j.Element> |
getElements(org.dom4j.Element parent,
String tagName)
Gets the descendant elements list from the parent element.
|
static String |
getElementValue(org.dom4j.Element element)
Gets the text value of current element.
|
static String |
getElementValue(org.dom4j.Element parent,
String tagName)
Gets the value of the child element by tag name under the given parent
element.
|
static org.dom4j.Element |
getRootElementFromFile(File xml)
Gets the root element from given XML file.
|
static org.dom4j.Element |
getRootElementFromStream(InputStream xml)
Gets the root element from input stream.
|
static org.dom4j.Element |
getRootElementFromString(String payload)
Gets the root element from the given XML payload.
|
static org.dom4j.Document |
newDocument()
Creates a new document instance.
|
static String |
nodeToString(org.dom4j.Node node)
Converts the Node/Element instance to XML payload.
|
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 org.dom4j.Document newDocument()
public static org.dom4j.Document getDocument(File file) throws SchemaException
file - the XML file instanceSchemaException - problem parsing the XML filepublic static org.dom4j.Document getDocument(InputStream xml) throws SchemaException
xml - file inputstreamSchemaException - problem parsing the XML filepublic static org.dom4j.Document getDocument(InputSource xml) throws SchemaException
xml - file InputSourceSchemaException - problem parsing the XML filepublic static org.dom4j.Element createRootElement(String tagName) throws SchemaException
tagName - the name of the root elementSchemaException - problem generating a new documentpublic static org.dom4j.Element getRootElementFromStream(InputStream xml) throws SchemaException
xml - the XML file input streamSchemaException - problem parsing the XML file input streampublic static org.dom4j.Element getRootElementFromFile(File xml) throws SchemaException
xml - the name of the XML fileSchemaException - problem parsing the XML filepublic static org.dom4j.Element getRootElementFromString(String payload) throws SchemaException
payload - the XML payload representing the XML file.SchemaException - problem parsing the XML payloadpublic static String xmlToString(File file) throws SchemaException
file - the XML file instanceSchemaException - problem transforming XML to stringpublic static List<org.dom4j.Element> getChildElements(org.dom4j.Element parent, String tagName)
parent - the parent element in the element treetagName - the specified tool namepublic static List<org.dom4j.Element> getElements(org.dom4j.Element parent, String tagName)
parent - the parent element in the element treetagName - the specified tool namepublic static org.dom4j.Element getElement(org.dom4j.Element parent,
String tagName)
parent - the parent element in the element treetagName - the specified tag name.public static org.dom4j.Element getChildElement(org.dom4j.Element parent,
String tagName)
parent - the parent element in the element treetagName - the specified tag namepublic static String getElementValue(org.dom4j.Element parent, String tagName)
parent - the parent elementtagName - the tag name of the child elementpublic static String getElementValue(org.dom4j.Element element)
element - parent the current elementpublic static String getAttributeValue(org.dom4j.Element current, String attrName)
current - current elementattrName - attribute name in current elementpublic static org.dom4j.Element appendElement(org.dom4j.Element parent,
String tagName)
parent - the parent elementtagName - the child element namepublic static void appendElement(org.dom4j.Element parent,
org.dom4j.Element child)
parent - the parent elementchild - the child element to appendpublic static String nodeToString(org.dom4j.Node node) throws SchemaException
node - the node/element instance to convertSchemaException - problem converting XML to stringpublic static String xmlToString(InputStream in) throws SchemaException
in - the XML file input streamSchemaException - problem transforming XML to stringCopyright © 2023. All rights reserved.