public class XmlUtils extends Object
| Constructor and Description |
|---|
XmlUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Element |
appendChild(Node node,
String tagName)
在已有节点上创建子节点
|
static String |
cleanInvalid(String xmlContent)
去除XML文本中的无效字符
|
static Object |
convertXmlStrToObject(String xml,
Class clazz)
将String类型的xml转换成对象
|
static DocumentBuilder |
createDocumentBuilder()
创建 DocumentBuilder
|
static Document |
createXml()
创建XML文档
创建的XML默认是utf8编码,修改编码的过程是在toStr和toFile方法里,既XML在转为文本的时候才定义编码 |
static Document |
createXml(String rootElementName)
创建XML文档
创建的XML默认是utf8编码,修改编码的过程是在toStr和toFile方法里,既XML在转为文本的时候才定义编码 |
static XPath |
createXPath()
创建XPath
Xpath相关文章:https://www.ibm.com/developerworks/cn/xml/x-javaxpathapi.html |
static String |
elementText(Element element,
String tagName)
根据节点名获得第一个子节点
|
static String |
elementText(Element element,
String tagName,
String defaultValue)
根据节点名获得第一个子节点
|
static String |
escape(String string)
转义XML特殊字符:
|
static Object |
getByXPath(String expression,
Object source,
QName returnType)
通过XPath方式读取XML节点等信息
Xpath相关文章:https://www.ibm.com/developerworks/cn/xml/x-javaxpathapi.html |
static Element |
getElement(Element element,
String tagName)
根据节点名获得第一个子节点
|
static Element |
getElementByXPath(String expression,
Object source)
通过XPath方式读取XML节点等信息
Xpath相关文章:https://www.ibm.com/developerworks/cn/xml/x-javaxpathapi.html |
String |
getfield(String str,
String field) |
static String |
getFieldByxml(String xml,
String field) |
static Node |
getNodeByXPath(String expression,
Object source)
通过XPath方式读取XML节点等信息
Xpath相关文章:https://www.ibm.com/developerworks/cn/xml/x-javaxpathapi.html |
static NodeList |
getNodeListByXPath(String expression,
Object source)
通过XPath方式读取XML的NodeList
Xpath相关文章:https://www.ibm.com/developerworks/cn/xml/x-javaxpathapi.html |
static Element |
getRootElement(Document doc)
获得XML文档根节点
|
static boolean |
isElement(Node node)
给定节点是否为
Element 类型节点 |
static Document |
mapToXml(Map<?,?> data,
String rootName)
将Map转换为XML
|
static String |
mapToXmlNosign(Map<String,Object> map)
将MAP对象转换为XML格式
|
static String |
parseBeanToXml(Object object)
将对象转换为XML
|
static String |
parseBeanToXml(Object object,
Map<String,Object> map,
Marshaller.Listener listener)
将对象转换为XML
|
static Object |
parseXmlToBean(String text,
Object javaBean)
将字符串装换为对象
|
static Object |
parseXmlToBean(String text,
Object javaBean,
String charset)
将字符串装换为对象
|
static <T> List<T> |
parseXmlToBeanList(String xml,
String rel,
Class<T> clazz)
将xml对象根据定义的节点进行拆分,并实现List对象转换
|
static <T> List<T> |
parseXmlToBeanList(String xml,
String rel,
Class<T> clazz,
boolean isSelect)
将xml对象根据定义的节点进行拆分,并实现List对象转换
|
static <T> T |
readObjectFromXml(InputSource source)
从XML中读取对象 Reads serialized object from the XML file.
|
static Document |
readXML(InputSource source)
读取解析XML文件
编码在XML中定义 |
static Document |
readXML(InputStream inputStream)
读取解析XML文件
编码在XML中定义 |
static Document |
readXML(Reader reader)
读取解析XML文件
|
static String |
replaceEscapeCharacter(String xml)
替换xml中特殊字符
|
String |
requestModel(Object esbEntry) |
static List<Element> |
transElements(Element parentEle,
NodeList nodeList)
将NodeList转换为Element列表
非Element节点将被忽略 |
static List<Element> |
transElements(NodeList nodeList)
将NodeList转换为Element列表
|
static <T> List<T> |
XMLToBeanList(String xml,
String rel,
Class<T> clazz)
xml转list
|
static String |
xmlToLowerCase(String xml)
将xml节点转小写
|
static Map<String,Object> |
xmlToMap(Node node)
XML格式字符串转换为Map
|
static Map<String,Object> |
xmlToMap(Node node,
Map<String,Object> result)
XML节点转换为Map
|
public static Document readXML(InputStream inputStream) throws CommonException
inputStream - XML流CommonException - IO异常或转换异常public static Document readXML(Reader reader) throws CommonException
reader - XML流CommonException - IO异常或转换异常public static Document readXML(InputSource source)
source - InputSourcepublic static <T> T readObjectFromXml(InputSource source)
T - 对象类型source - InputSourcepublic static Document createXml()
public static DocumentBuilder createDocumentBuilder()
public static Document createXml(String rootElementName)
rootElementName - 根节点名称public static Element getRootElement(Document doc)
doc - DocumentDocument.getDocumentElement()public static String cleanInvalid(String xmlContent)
xmlContent - XML文本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 - 节点名defaultValue - 默认值public static List<Element> transElements(NodeList nodeList)
nodeList - NodeListpublic static List<Element> transElements(Element parentEle, NodeList nodeList)
parentEle - 父节点,如果指定将返回此节点的所有直接子节点,nul返回所有就节点nodeList - NodeListpublic static XPath createXPath()
XPathpublic static Element getElementByXPath(String expression, Object source)
expression - XPath表达式source - 资源,可以是Docunent、Node节点等public static NodeList getNodeListByXPath(String expression, Object source)
expression - XPath表达式source - 资源,可以是Docunent、Node节点等public static Node getNodeByXPath(String expression, Object source)
expression - XPath表达式source - 资源,可以是Docunent、Node节点等public static Object getByXPath(String expression, Object source, QName returnType)
expression - XPath表达式source - 资源,可以是Docunent、Node节点等returnType - 返回类型,XPathConstantspublic static String escape(String string)
& (ampersand) 替换为 & < (小于) 替换为 < > (大于) 替换为 > " (双引号) 替换为 "
string - 被替换的字符串public static Map<String,Object> xmlToMap(Node node)
node - XML节点public static Map<String,Object> xmlToMap(Node node, Map<String,Object> result)
node - XML节点result - 结果Map类型public static Document mapToXml(Map<?,?> data, String rootName)
data - Map类型数据rootName - 节点public static boolean isElement(Node node)
Element 类型节点node - 节点Element 类型节点public static Element appendChild(Node node, String tagName)
node - 节点tagName - 标签名public static Object parseXmlToBean(String text, Object javaBean)
text - 字符串javaBean - 对象public static Object parseXmlToBean(String text, Object javaBean, String charset)
text - 字符串javaBean - 对象charset - 编码public static Object convertXmlStrToObject(String xml, Class clazz)
xml - 字符串clazz - 对象public static <T> List<T> parseXmlToBeanList(String xml, String rel, Class<T> clazz, boolean isSelect)
T - 对象xml - 字符串rel - 拆分节点clazz - 对象信息isSelect - 是否拆分public static <T> List<T> parseXmlToBeanList(String xml, String rel, Class<T> clazz)
T - 对象xml - 字符串rel - 拆分节点clazz - 对象信息public static String parseBeanToXml(Object object) throws Exception
object - 对象信息Exception - 异常public static String parseBeanToXml(Object object, Map<String,Object> map, Marshaller.Listener listener) throws Exception
object - 对象信息map - maplistener - ListenerException - 异常public static String replaceEscapeCharacter(String xml)
xml - 字符串信息public static String mapToXmlNosign(Map<String,Object> map)
map - 对象信息public static <T> List<T> XMLToBeanList(String xml, String rel, Class<T> clazz)
T - 对象xml - 字符串rel - 拆分节点clazz - 对象public static String xmlToLowerCase(String xml)
xml - 字符串public static String getFieldByxml(String xml, String field)
xml - 字符串field - 要获取的字段名public String requestModel(Object esbEntry) throws JAXBException
JAXBExceptionCopyright © 2019. All rights reserved.