1 JAVA代码生成XML框架
主要依赖
com.thoughtworks.xstream
xstream
1.4.20
2 代码如下, 主要是内部标签嵌套规则, 还可以把XML对象转换成bean对象
package cn.djrj.web.controller.indicatorManage.xml.module;
import cn.djrj.common.utils.StringUtils;
import cn.djrj.system.domain.SysUseModule;
import cn.djrj.system.domain.SysUseModuleParam;
import com.google.common.collect.ImmutableMap;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.Xpp3Driver;
import java.util.*;
import java.util.stream.Collectors;
public class ModuleCombineUtil {
public static void main(String args[]) {
List list = getSysIndicatorCombines();
List shortlist = getShortbar();
List weblist = getWebTag();
toXML(list,shortlist,weblist);
}
//组装生成XML文件的功能配置
public static String createXML(List list, Map configParam) {
if (null == list || list.isEmpty()) {
throw new RuntimeException("创建XML的参数为空,无法生成");
}
// 生成menu标签
List itemList = new ArrayList<>();
// 生成shorbar标签
List shortBarList = new ArrayList<>();
// 生成web标签
List webList = new ArrayList<>();
// shortbar 一级目录
ShortbarItem shortbarItem = new ShortbarItem();
shortbarItem.setType(3);
shortbarItem.setSort(100);
shortBarList.add(shortbarItem);
list.forEach(sysUseModule -> {
Map configParams;
//menu标签 功能类型
//if (null != sysUseModule.getUseType() && "0".equals(sysUseModule.getUseType()) || "3".equals(sysUseModule.getUseType()) ) {
//导航区域,0=顶部
if (null != sysUseModule.getNavigationArea() && "0".equals(sysUseModule.getNavigationArea())){
//menu 标签
extractedMenu(configParam, itemList, sysUseModule);
} else if (null != sysUseModule.getNavigationArea() ) { // shortbar标签
//导航1
if ("1".equals(sysUseModule.getNavigationArea())) {
configParams = new HashMap<>();
getStrToMap(sysUseModule.getModuleParamId(), configParam,configParams);
ShortbarItem shortbarItem0 = new ShortbarItem();
shortbarItem0.setTitle(sysUseModule.getName());
shortbarItem0.setType(0);
shortbarItem0.setImage(configParams.getOrDefault("image", null));
shortbarItem0.setImageSel(configParams.getOrDefault("image_sel", null));
shortbarItem0.setCmd(configParams.getOrDefault("cmd", null));
shortbarItem0.setTip(sysUseModule.getCode());
//间距特殊处理
shortbarItem0.setSeparator(configParams.getOrDefault("separator", null) != null ? true : null);
shortbarItem0.setFunType(configParams.getOrDefault("funType", null) == null ? null : Integer.valueOf(configParams.get("funType")));
shortbarItem0.setType(configParams.getOrDefault("type", null) == null ? 0 : Integer.parseInt(configParams.get("type")));
shortbarItem0.setSort(0);
if (null != configParams.getOrDefault("separator", null) && configParams.getOrDefault("funType", null) == null) {
shortbarItem0.setType(1);
shortbarItem0.setTitle("");
shortbarItem0.setImage(null);
shortbarItem0.setImageSel(null);
shortbarItem0.setCmd(null);
shortbarItem0.setTip(null);
shortbarItem0.setSeparator(true);
}
shortbarItem0.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());
shortBarList.add(shortbarItem0);
} else if (Arrays.asList(new String[]{"2", "3", "4"}).contains(sysUseModule.getNavigationArea())) {
Map paramChildernMap = getStrToMapChildern(sysUseModule.getModuleParamId(), configParam,sysUseModule.getNavigationArea());
//二级目录
ShortbarItem shortbarItem2 = new ShortbarItem();
shortbarItem2.setTitle(sysUseModule.getName());
shortbarItem2.setType(1);
if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
shortbarItem2.setType(4);
}
shortbarItem2.setImage(paramChildernMap.getOrDefault("image", null));
shortbarItem2.setImageSel(paramChildernMap.getOrDefault("image_sel", null));
shortbarItem2.setCmd(paramChildernMap.getOrDefault("cmd", null));
//生成XML的CMD固定属性
if (null != sysUseModule.getUseType() && "3".equals(sysUseModule.getUseType())) {
shortbarItem2.setCmd("zbzh:" + sysUseModule.getName());
}
shortbarItem2.setImageHover(paramChildernMap.getOrDefault("image_hover", null));
shortbarItem2.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());
shortbarItem.getItem().add(shortbarItem2);
if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
// 三级目录数据转换
for (SysUseModule module : sysUseModule.getChildern()) {
configParams = new HashMap<>();
getStrToMap(module.getModuleParamId(), configParam,configParams);
ShortbarItem shortChildern = new ShortbarItem();
shortChildern.setTitle(module.getName());
shortChildern.setTip(module.getCode());
shortChildern.setType(1);
//shortChildern.setImage(configParams.getOrDefault("image", null));
//shortChildern.setImageSel(configParams.getOrDefault("image_sel", null));
shortChildern.setCmd(configParams.getOrDefault("cmd", null));
//shortChildern.setImageHover(configParams.getOrDefault("image_hover", null));
shortChildern.setContext(configParam.getOrDefault(module.getModuleParamId(), new SysUseModuleParam()).getContext());
shortbarItem2.getItem().add(shortChildern);
}
}
}
}
// web标签
if (null != sysUseModule.getUseType() && "1".equals(sysUseModule.getUseType())) {
extractedTOweb(configParam, webList, sysUseModule,false);
}
// 二级网页
if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
for (SysUseModule module : sysUseModule.getChildern()) {
if (null != module.getUseType() && "1".equals(module.getUseType())) {
extractedTOweb(configParam, webList, module,false);
}
}
}
});
return toXML(itemList, shortBarList.stream().sorted(Comparator.comparing(ShortbarItem::getSort)).collect(Collectors.toList()), webList);
}
// menu功能菜单
private static void extractedMenu(Map configParam, List itemList, SysUseModule sysUseModule) {
Map configParams;
ItemSet itemSet = new ItemSet();
itemSet.setTitle(sysUseModule.getName());
itemSet.setTip(sysUseModule.getCode());
configParams = new HashMap<>();
getStrToMap(sysUseModule.getModuleParamId(), configParam,configParams);
itemSet.setCmd(configParams.getOrDefault("cmd", null));
if (null != configParams.getOrDefault("sel", null)) {
itemSet.setSel(Integer.valueOf(configParams.get("sel")));
}
itemSet.setType(0);
itemSet.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());
if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
// 二级目录数据转换
for (SysUseModule module : sysUseModule.getChildern()) {
configParams = new HashMap<>();
getStrToMap(module.getModuleParamId(), configParam,configParams);
ItemSet itemChildern = new ItemSet();
itemChildern.setTitle(module.getName());
itemChildern.setFunType(1);
itemChildern.setTip(module.getCode());
itemChildern.setCmd(configParams.getOrDefault("cmd", null));
//生成XML的CMD固定属性
if (null != module.getUseType() && "3".equals(module.getUseType())) {
itemChildern.setCmd("zbzh:" + module.getName());
}
//间距特殊处理
itemChildern.setSeparator(configParams.getOrDefault("separator", null) != null ? true : null);
itemChildern.setFunType(configParams.getOrDefault("funType", null) == null ? null : Integer.valueOf(configParams.get("funType")));
//分隔符处理
if (null != configParams.getOrDefault("separator", null) && configParams.getOrDefault("funType", null) == null) {
itemChildern.setType(1);
itemChildern.setFunType(null);
itemChildern.setTitle("");
itemChildern.setTip(null);
itemChildern.setCmd(null);
itemChildern.setSeparator(true);
}
itemChildern.setContext(configParam.getOrDefault(module.getModuleParamId(), new SysUseModuleParam()).getContext());
itemSet.getItem().add(itemChildern);
}
itemSet.setFunType(2);
}
itemList.add(itemSet);
}
// web标签封装数据
private static void extractedTOweb(Map configParam, List webList, SysUseModule sysUseModule,boolean flag) {
Map paramWebMap = new HashMap<>();
getStrToMap(sysUseModule.getModuleParamId(), configParam,paramWebMap);
UrlTag web = new UrlTag();
web.setTitle(sysUseModule.getName());
web.setTip(sysUseModule.getCode());
if ("1".equals(sysUseModule.getOpenType())) {
web.setOpen(2);
} else if ("2".equals(sysUseModule.getOpenType())) {
web.setOpen(1);
}
web.setOpen(0);
web.setWeb(sysUseModule.getUrl());
web.setId(paramWebMap.getOrDefault("id", null));
web.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());
if (StringUtils.isNotBlank(sysUseModule.getConfigXmlParam())) {
String[] str = sysUseModule.getConfigXmlParam().split(",");
for (String p : str) {
Ptag ptag = new Ptag();
ptag.setType(p);
web.getP().add(ptag);
}
}
webList.add(web);
if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0 && flag) {
for (SysUseModule module : sysUseModule.getChildern()) {
paramWebMap = new HashMap<>();
getStrToMap(module.getModuleParamId(), configParam,paramWebMap);
UrlTag webChildern = new UrlTag();
webChildern.setTitle(module.getName());
webChildern.setTip(module.getCode());
if ("1".equals(module.getOpenType())) {
webChildern.setOpen(2);
} else if ("2".equals(module.getOpenType())) {
webChildern.setOpen(1);
}
webChildern.setOpen(0);
webChildern.setWeb(module.getUrl());
webChildern.setContext(configParam.getOrDefault(module.getModuleParamId(), new SysUseModuleParam()).getContext());
webChildern.setId(paramWebMap.getOrDefault("id", null));
if (StringUtils.isNotBlank(module.getConfigXmlParam())) {
String[] str = module.getConfigXmlParam().split(",");
for (String p : str) {
Ptag ptag = new Ptag();
ptag.setType(p);
webChildern.getP().add(ptag);
}
}
webList.add(webChildern);
}
}
}
public static String toXML(List list,List shortbarItemList,List weblist) {
Config config = new Config();
// menu标签
Menu menu = new Menu();
config.setMenu(menu);
menu.setItem(list);
// Shortbar标签
Shortbar shortbar = new Shortbar();
config.setShortbar(shortbar);
shortbar.setItem(shortbarItemList);
// Web标签
Web web = new Web();
config.setWeb(web);
web.setUrl(weblist);
//special 标签
Special special = new Special();
config.setSpecial(special);
special.setZh(getSpecialZhTag());
//fs_main 标签
FsMain fsMain = new FsMain();
config.setFs_main(fsMain);
fsMain.setZh(getFsMainTag());
//fs_sub 标签
FsSub fsSub = new FsSub();
config.setFs_sub(fsSub);
fsSub.setZh(getfsSubZhTag());
//kx_main 标签
KxMain kxMain = new KxMain();
config.setKx_main(kxMain);
kxMain.setZh(getkxMainTag());
//kx_sub 标签
KxSub kxsub = new KxSub();
config.setKx_sub(kxsub);
kxsub.setZh(getKxSubZhTag());
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder()));
//不加设置, 注解别名不生效
xStream.autodetectAnnotations(true);
xStream.alias("config", Config.class);
xStream.alias("menu", Menu.class);
xStream.alias("item", ItemSet.class);
/ ignore
/* xStream.omitField(ItemSet.class, "draw");;*/
// menu 标签 list数据属性
xStream.addImplicitCollection(Menu.class, "item", "item", ItemSet.class);
xStream.useAttributeFor(ItemSet.class, "title");
xStream.useAttributeFor(ItemSet.class, "type");
xStream.useAttributeFor(ItemSet.class, "sel");
xStream.useAttributeFor(ItemSet.class, "funType");
xStream.useAttributeFor(ItemSet.class, "tip");
xStream.useAttributeFor(ItemSet.class, "cmd");
xStream.useAttributeFor(ItemSet.class, "separator");
xStream.useAttributeFor(ItemSet.class, "context");
xStream.omitField(ItemSet.class, "context");
xStream.addImplicitCollection(ItemSet.class, "item");
// shortbar 标签
xStream.addImplicitCollection(Shortbar.class, "item", "item", ShortbarItem.class);
xStream.alias("shortbar", Shortbar.class);
xStream.alias("item", ShortbarItem.class);
//xStream.aliasField("image_sel",ShortbarItem.class,"image_sel");
xStream.useAttributeFor(ShortbarItem.class, "title");
xStream.useAttributeFor(ShortbarItem.class, "image");
xStream.useAttributeFor(ShortbarItem.class, "imageSel");
xStream.useAttributeFor(ShortbarItem.class, "type");
xStream.useAttributeFor(ShortbarItem.class, "funType");
xStream.useAttributeFor(ShortbarItem.class, "cmd");
xStream.useAttributeFor(ShortbarItem.class, "tip");
xStream.useAttributeFor(ShortbarItem.class, "separator");
xStream.useAttributeFor(ShortbarItem.class, "imageHover");
xStream.omitField(ShortbarItem.class, "sort");
xStream.useAttributeFor(ShortbarItem.class, "context");
xStream.omitField(ShortbarItem.class, "context");
xStream.addImplicitCollection(ShortbarItem.class, "item");
// web标签
xStream.alias("web", Web.class);
xStream.alias("url", UrlTag.class);
xStream.useAttributeFor(UrlTag.class, "title");
xStream.useAttributeFor(UrlTag.class, "web");
xStream.useAttributeFor(UrlTag.class, "open");
xStream.useAttributeFor(UrlTag.class, "fixed");
xStream.useAttributeFor(UrlTag.class, "tip");
xStream.useAttributeFor(UrlTag.class, "id");
xStream.useAttributeFor(UrlTag.class, "context");
xStream.omitField(UrlTag.class, "context");
xStream.addImplicitCollection(Web.class, "url");
xStream.addImplicitCollection(UrlTag.class, "p", "p", Ptag.class);
xStream.useAttributeFor(Ptag.class, "type");
//special 标签
xStream.alias("special", Special.class);
xStream.alias("zh", SpeZh.class);
xStream.useAttributeFor(SpeZh.class, "title");
xStream.useAttributeFor(SpeZh.class, "isMain");
xStream.useAttributeFor(SpeZh.class, "type");
xStream.addImplicitCollection(Special.class, "zh");
//fs_main 标签
xStream.alias("fs_main", FsMain.class);
xStream.alias("zh", Title.class);
xStream.useAttributeFor(Title.class,"title");
xStream.useAttributeFor(Title.class,"context");
//xStream.addImplicitCollection(Title.class, "title");
xStream.addImplicitCollection(FsMain.class, "zh");
//fs_sub 标签
xStream.alias("fs_sub", FsSub.class);
xStream.alias("zh", ZhSub.class);
xStream.useAttributeFor(ZhSub.class, "title");
xStream.addImplicitCollection(FsSub.class, "zh");
//kx_main 标签
xStream.alias("kx_main", KxMain.class);
xStream.alias("zh", ZhSub.class);
xStream.useAttributeFor(Title.class, "title");
xStream.addImplicitCollection(KxMain.class, "zh");
//kx_sub 标签
xStream.alias("kx_sub", KxSub.class);
xStream.alias("zh", ZhSub.class);
xStream.useAttributeFor(Title.class, "title");
xStream.addImplicitCollection(KxSub.class, "zh");
String string = xStream.toXML(config);
String xml = " \n";
//System.out.println(xml + string);
return xml + string;
}
private static List getSysIndicatorCombines() {
ItemSet itemSet = new ItemSet();
itemSet.setTitle("海王体验版");
itemSet.setSel(100);
itemSet.setFunType(1000);
itemSet.setType(10000);
ItemSet itemSet001 = new ItemSet();
itemSet001.setSel(1100);
itemSet001.setFunType(11000);
itemSet001.setType(110000);
itemSet.getItem().add(itemSet001);
/
ItemSet itemSet1 = new ItemSet();
itemSet1.setTitle("赢家体验版");
itemSet1.setSel(200);
itemSet1.setFunType(2000);
itemSet1.setType(20000);
ItemSet itemSet002 = new ItemSet();
itemSet002.setSel(2200);
itemSet002.setFunType(22000);
itemSet002.setType(220000);
itemSet1.getItem().add(itemSet002);
List list = new ArrayList<>();
list.add(itemSet);
list.add(itemSet1);
return list;
}
private static List getShortbar() {
//一级功能
ShortbarItem itemSet = new ShortbarItem();
itemSet.setTitle("交易");
itemSet.setImageSel("100");
itemSet.setFunType(1000);
itemSet.setType(0);
//二级功能
/*
ShortbarItem itemSet001 = new ShortbarItem();
itemSet001.setImageSel("1100");
itemSet001.setFunType(11000);
itemSet001.setType(110000);
itemSet.getItem().add(itemSet001);
*/
/一级功能
ShortbarItem itemSet1 = new ShortbarItem();
itemSet1.setType(3);
itemSet1.setFunType(null);
//二级功能
ShortbarItem itemSet002 = new ShortbarItem();
itemSet002.setImageSel("2200");
itemSet002.setFunType(22000);
itemSet002.setType(220000);
itemSet1.getItem().add(itemSet002);
//三级功能
ShortbarItem itemSet003 = new ShortbarItem();
itemSet003.setImageSel("3300");
itemSet003.setFunType(33000);
itemSet003.setType(330000);
itemSet002.getItem().add(itemSet003);
List list = new ArrayList<>();
list.add(itemSet);
list.add(itemSet1);
return list;
}
private static List getWebTag() {
//一级功能
UrlTag itemSet = new UrlTag();
itemSet.setTitle("F10");
itemSet.setWeb("www.baidu.com");
itemSet.setOpen(11);
itemSet.setFixed("true");
//二级功能
Ptag itemSet001 = new Ptag();
itemSet001.setType("broker");
Ptag itemSet002 = new Ptag();
itemSet002.setType("stock");
itemSet.getP().add(itemSet001);
itemSet.getP().add(itemSet002);
/一级功能
UrlTag itemSet1 = new UrlTag();
itemSet1.setTitle("自选资讯");
itemSet1.setWeb("http://basic.10jqka.com.cn/");
itemSet1.setOpen(22);
itemSet1.setFixed("false");
//二级功能
/* Ptag itemSet002 = new Ptag();
itemSet002.setImageSel("2200");
itemSet002.setFunType(22000);
itemSet002.setType(220000);
itemSet1.getItem().add(itemSet002);*/
List list = new ArrayList<>();
list.add(itemSet);
list.add(itemSet1);
return list;
}
private static List getSpecialZhTag() {
List zhList = new ArrayList<>();
zhList.add(new SpeZh("MACD","0"));
zhList.add(new SpeZh("DMI","0"));
zhList.add(new SpeZh("DMA","0"));
zhList.add(new SpeZh("FSL","0"));
zhList.add(new SpeZh("TRIX","0"));
zhList.add(new SpeZh("BRAR","0"));
zhList.add(new SpeZh("CR","0"));
zhList.add(new SpeZh("VR","0"));
zhList.add(new SpeZh("OBV","0"));
zhList.add(new SpeZh("ASI","0"));
zhList.add(new SpeZh("EMV","0"));
zhList.add(new SpeZh("VOL","0"));
zhList.add(new SpeZh("RSI","0"));
zhList.add(new SpeZh("WR","0"));
zhList.add(new SpeZh("KDJ","0"));
zhList.add(new SpeZh("CCI","0"));
zhList.add(new SpeZh("ROC","0"));
zhList.add(new SpeZh("MTM","0"));
zhList.add(new SpeZh("BOLL","0"));
zhList.add(new SpeZh("PSY","0"));
zhList.add(new SpeZh("MA", "1", "fxt"));
zhList.add(new SpeZh("MA2", "1", "fxt"));
zhList.add(new SpeZh("EXPMA", "1", "fxt"));
zhList.add(new SpeZh("BBIBOLL", "1", "fxt"));
return zhList;
}
private static List getfsSubZhTag() {
List zhList = new ArrayList<>();
zhList.add(new ZhSub("MACD"));
zhList.add(new ZhSub("KDJ"));
zhList.add(new ZhSub("BOLL"));
zhList.add(new ZhSub("DMI"));
zhList.add(new ZhSub("WR"));
return zhList;
}
private static List getkxMainTag() {
List zhList = new ArrayList<>();
zhList.add(new ZhSub("MA"));
zhList.add(new ZhSub("MA2"));
zhList.add(new ZhSub("EXPMA"));
zhList.add(new ZhSub("BBIBOLL"));
return zhList;
}
private static List getKxSubZhTag() {
List zhList = new ArrayList<>();
zhList.add(new ZhSub("MACD"));
zhList.add(new ZhSub("DMI"));
zhList.add(new ZhSub("DMA"));
zhList.add(new ZhSub("FSL"));
zhList.add(new ZhSub("TRIX"));
zhList.add(new ZhSub("BRAR"));
zhList.add(new ZhSub("CR"));
zhList.add(new ZhSub("VR"));
zhList.add(new ZhSub("OBV"));
zhList.add(new ZhSub("ASI"));
zhList.add(new ZhSub("EMV"));
zhList.add(new ZhSub("VOL"));
zhList.add(new ZhSub("RSI"));
zhList.add(new ZhSub("WR"));
zhList.add(new ZhSub("KDJ"));
zhList.add(new ZhSub("CCI"));
zhList.add(new ZhSub("ROC"));
zhList.add(new ZhSub("MTM"));
zhList.add(new ZhSub("BOLL"));
zhList.add(new ZhSub("PSY"));
return zhList;
}
private static List getFsMainTag() {
List titles = new ArrayList<>();
Title ti = new Title();
ti.setTitle("MA");
// ti.setContext("name=MACD,isMain=0");
titles.add(ti);
return titles;
}
private static void getStrToMap(Long id,Map configParam,Map configParams) {
if (null == id) {
return;
}
Map map = configParams == null || configParams.isEmpty() ? new HashMap<>() : configParams;
SysUseModuleParam paramMap = (SysUseModuleParam) configParam.getOrDefault(id, null);
if (null != paramMap && StringUtils.isNotBlank(paramMap.getContext())) {
// 拼装固定参数
// String str = "image=ShortBar,image_sel=ShortBar";
String[] pairs = paramMap.getContext().split("&");
for (String pair : pairs) {
String[] keyValue = pair.split("=");
configParams.put(keyValue[0], keyValue[1]);
}
}
}
private static Map getStrToMapChildern(Long id,Map configParam,String areaValue) {
if (null == id) {
return new HashMap<>();
}
Map map = new HashMap<>();
SysUseModuleParam paramMap = (SysUseModuleParam) configParam.getOrDefault(id, null);
if (null != paramMap && StringUtils.isNotBlank(paramMap.getContext())) {
// 拼装固定参数
if (StringUtils.isNotBlank(areaValue)) {
if (null != PARAM_AREA_MAP.getOrDefault(areaValue, null)) {
paramMap.setContext(paramMap.getContext() + "&" + PARAM_AREA_MAP.getOrDefault(areaValue, null));
}
}
// String str = "image=ShortBar,image_sel=ShortBar";
String[] pairs = paramMap.getContext().split("&");
for (String pair : pairs) {
String[] keyValue = pair.split("=");
map.put(keyValue[0], keyValue[1]);
}
}
// System.out.println(map);
return map;
}
public static Map PARAM_AREA_MAP = ImmutableMap.builder()
.put("2","image=#B19659&image_sel=#FFC10A&image_hover=#FFDA88")
.put("3","image=#926995&image_sel=#F7A1FF&image_hover=#F9AAFF")
.put("4","image=#61709C&image_sel=#B5C8FF&image_hover=#94AFFF").build();
/* 手拼成XML生成方式
private String createXML(List list){
String[] types = new String[]{"CONCEPT-概念", "FGBK-风格", "DYBK-地域", "HYBK-行业"};
//创建document
Document document = DocumentHelper.createDocument();
//创建根节点
Element root = DocumentHelper.createElement("config");
document.setRootElement(root);
//创建根节点下的子节点
for (String type : types) {
Element bigblock = root.addElement("bigblock");
bigblock.addAttribute("code", type.split("-")[0]);
bigblock.addAttribute("setcode", "");
bigblock.addAttribute("name", "");
}
return document.getXMLEncoding();
}*/
}
生成XML如下
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-