|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.xiaoleilu.hutool.XmlUtil
public class XmlUtil
XML工具类
此工具使用w3c dom工具,不需要依赖第三方包。
| 字段摘要 | |
|---|---|
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 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
public static final String INVALID_REGEX
| 构造方法详细信息 |
|---|
public XmlUtil()
| 方法详细信息 |
|---|
public static Document readXML(File file)
file - XML文件
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 String xmlToStr(Document doc)
doc - 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 - NodeList
public static List<Element> transElements(Element parentEle,
NodeList nodeList)
parentEle - 父节点,如果指定将返回此节点的所有直接子节点,nul返回所有就节点nodeList - NodeList
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||