public class XmlUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
INVALID_REGEX
在XML中无效的字符 正则
|
| 构造器和说明 |
|---|
XmlUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
cleanInvalid(String xmlContent)
去除XML文本中的无效字符
|
static Document |
createXml(String rootElementName)
创建XML文档
|
static String |
elementText(Element element,
String tagName)
根据节点名获得第一个子节点
|
static String |
elementText(Element element,
String tagName,
String defaultValue)
根据节点名获得第一个子节点
|
static Element |
getElement(Element element,
String tagName)
根据节点名获得第一个子节点
|
static List<Element> |
getElements(Element element,
String tagName)
根据节点名获得子节点列表
|
static Document |
parseXml(String xmlStr)
将String类型的XML转换为XML文档
|
static Document |
parseXml(String xmlStr,
String charset)
将String类型的XML转换为XML文档
|
static Document |
readXML(File file)
读取解析XML文件
|
static Document |
readXML(String absoluteFilePath)
读取解析XML文件
|
static List<Element> |
transElements(Element parentEle,
NodeList nodeList)
将NodeList转换为Element列表
|
static List<Element> |
transElements(NodeList nodeList)
将NodeList转换为Element列表
|
static void |
xmlToFile(Document doc,
String absolutePath,
String charset)
将XML文档写入到文件
|
static String |
xmlToStr(Document doc)
将XML文档转换为String
|
public static Document readXML(String absoluteFilePath)
absoluteFilePath - XML文件绝对路径public static Document parseXml(String xmlStr, String charset)
xmlStr - XML字符串charset - public static Document parseXml(String xmlStr)
xmlStr - XML字符串public static void xmlToFile(Document doc, String absolutePath, String charset)
doc - XML文档absolutePath - 文件绝对路径,不存在会自动创建charset - 字符集public static Document createXml(String rootElementName)
rootElementName - 根节点名称public static String cleanInvalid(String xmlContent)
xmlContent - XML文本public static List<Element> getElements(Element element, String tagName)
element - 节点tagName - 节点名public static Element getElement(Element element, String tagName)
element - 节点tagName - 节点名public static String elementText(Element element, String tagName)
element - 节点tagName - 节点名public static String elementText(Element element, String tagName, String defaultValue)
element - 节点tagName - 节点名public static List<Element> transElements(NodeList nodeList)
nodeList - NodeListCopyright © 2015. All rights reserved.