Merge pull request #599 from ddatsh/v5-dev

support xml namespace
This commit is contained in:
Golden Looly 2019-10-25 16:16:06 +08:00 committed by GitHub
commit 174e6cb53d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -744,6 +744,18 @@ public class XmlUtil {
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
*
@ -753,8 +765,21 @@ public class XmlUtil {
* @since 4.0.9
*/
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 Element root = appendChild(doc, rootName);
final Element root = appendChild(doc, rootName, namespace);
mapToXml(doc, root, data);
return doc;
@ -779,9 +804,9 @@ public class XmlUtil {
* @return 子节点
* @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();
Element child = doc.createElement(tagName);
Element child = doc.createElementNS(namespace, tagName);
node.appendChild(child);
return child;
}