mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-04 12:47:59 +08:00
commit
174e6cb53d
@ -744,6 +744,18 @@ public class XmlUtil {
|
|||||||
return toStr(mapToXml(data, rootName));
|
return toStr(mapToXml(data, rootName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Map转换为XML格式的字符串
|
||||||
|
*
|
||||||
|
* @param data Map类型数据
|
||||||
|
* @param rootName 根节点名
|
||||||
|
* @return XML格式的字符串
|
||||||
|
* @since 5.0.4
|
||||||
|
*/
|
||||||
|
public static String mapToXmlStr(Map<?, ?> data, String rootName,String namespace) {
|
||||||
|
return toStr(mapToXml(data, rootName, namespace));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将Map转换为XML
|
* 将Map转换为XML
|
||||||
*
|
*
|
||||||
@ -753,8 +765,21 @@ public class XmlUtil {
|
|||||||
* @since 4.0.9
|
* @since 4.0.9
|
||||||
*/
|
*/
|
||||||
public static Document mapToXml(Map<?, ?> data, String rootName) {
|
public static Document mapToXml(Map<?, ?> data, String rootName) {
|
||||||
|
|
||||||
|
return mapToXml(data, rootName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Map转换为XML
|
||||||
|
*
|
||||||
|
* @param data Map类型数据
|
||||||
|
* @param rootName 根节点名
|
||||||
|
* @return XML
|
||||||
|
* @since 5.0.4
|
||||||
|
*/
|
||||||
|
public static Document mapToXml(Map<?, ?> data, String rootName,String namespace) {
|
||||||
final Document doc = createXml();
|
final Document doc = createXml();
|
||||||
final Element root = appendChild(doc, rootName);
|
final Element root = appendChild(doc, rootName, namespace);
|
||||||
|
|
||||||
mapToXml(doc, root, data);
|
mapToXml(doc, root, data);
|
||||||
return doc;
|
return doc;
|
||||||
@ -779,9 +804,9 @@ public class XmlUtil {
|
|||||||
* @return 子节点
|
* @return 子节点
|
||||||
* @since 4.0.9
|
* @since 4.0.9
|
||||||
*/
|
*/
|
||||||
public static Element appendChild(Node node, String tagName) {
|
public static Element appendChild(Node node, String tagName, String namespace) {
|
||||||
Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument();
|
Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument();
|
||||||
Element child = doc.createElement(tagName);
|
Element child = doc.createElementNS(namespace, tagName);
|
||||||
node.appendChild(child);
|
node.appendChild(child);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user