java使用xstream框架生成xml文件

2023-12-12 05:45

本文主要是介绍java使用xstream框架生成xml文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 JAVA代码生成XML框架

主要依赖

        <dependency><groupId>com.thoughtworks.xstream</groupId><artifactId>xstream</artifactId><version>1.4.20</version></dependency>

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<ItemSet> list = getSysIndicatorCombines();List<ShortbarItem> shortlist = getShortbar();List<UrlTag> weblist = getWebTag();toXML(list,shortlist,weblist);}//组装生成XML文件的功能配置public static String createXML(List<SysUseModule> list, Map<Long, SysUseModuleParam> configParam) {if (null == list || list.isEmpty()) {throw new RuntimeException("创建XML的参数为空,无法生成");}// 生成menu标签List<ItemSet> itemList = new ArrayList<>();// 生成shorbar标签List<ShortbarItem> shortBarList = new ArrayList<>();// 生成web标签List<UrlTag> webList = new ArrayList<>();// shortbar 一级目录ShortbarItem shortbarItem = new ShortbarItem();shortbarItem.setType(3);shortbarItem.setSort(100);shortBarList.add(shortbarItem);list.forEach(sysUseModule -> {Map<String, String> 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标签//导航1if ("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<String, String> 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<Long, SysUseModuleParam> configParam, List<ItemSet> itemList, SysUseModule sysUseModule) {Map<String, String> 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<Long, SysUseModuleParam> configParam, List<UrlTag> webList, SysUseModule sysUseModule,boolean flag) {Map<String, String> 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<ItemSet> list,List<ShortbarItem> shortbarItemList,List<UrlTag> 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n";//System.out.println(xml + string);return xml + string;}private static List<ItemSet> 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<ItemSet> list = new ArrayList<>();list.add(itemSet);list.add(itemSet1);return list;}private static List<ShortbarItem> 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<ShortbarItem> list = new ArrayList<>();list.add(itemSet);list.add(itemSet1);return list;}private static List<UrlTag> 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<UrlTag> list = new ArrayList<>();list.add(itemSet);list.add(itemSet1);return list;}private static List<SpeZh> getSpecialZhTag() {List<SpeZh> 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<ZhSub> getfsSubZhTag() {List<ZhSub> 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<ZhSub> getkxMainTag() {List<ZhSub> 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<ZhSub> getKxSubZhTag() {List<ZhSub> 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<Title> getFsMainTag() {List<Title> 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<String, String> 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<String,String> getStrToMapChildern(Long id,Map configParam,String areaValue) {if (null == id) {return new HashMap<>();}Map<String, String> 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<String, String> PARAM_AREA_MAP = ImmutableMap.<String, String>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<ItemSet> list){String[] types = new String[]{"CONCEPT-概念", "FGBK-风格", "DYBK-地域", "HYBK-行业"};//创建documentDocument 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如下

<?xml version="1.0" encoding="UTF-8" ?>
<config><menu><item title="决策" funType=2><item title="市场热点" funType=1 shortcut="SCRD" cmd="cmd:25"/><item title="行情异动" funType=1 shortcut="HQYD"  cmd="cmd:65"/><item title="" type=1 separator=true /><item title="龙头掘金" cmd="cmd:69" right="300"/><item title="" type=1 separator=true /><item title="资金监控" cmd="zbzh:资金监控"/></item><item title="发现" funType=2><item title="未来大事" funType=1 cmd="web"/><item title="事件驱动" funType=1 cmd="web"/><item title="盘口异动" funType=1 cmd="web"/><item title="个股避雷" funType=1 cmd="web"/></item><item title="交易" cmd="trade"/></menu><shortbar><item title="首页" image="ShortBar/new_sy" image_sel="ShortBar/new_sy" type=0 funType=0 cmd="cmd:3"/><item title="" image="ShortBar/jy" image_sel="ShortBar/jy" type=-1 separator=true funType=6 /><item type =2><item title="自选股" tip="自选股" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:16,9002,-1,0"><item title="自选股" tip="自选股" cmd="cmd:16,9002,-1,0"/><item title="最近浏览" tip="最近浏览" cmd="cmd:16,9114,-1,0"/></item><item title="全景图" tip="全景图" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:3"><item title="全景图" tip="全景图" cmd="cmd:3"/></item></item><item type =2><item title="大盘" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:67"><item title="中证500" cmd="cmd:2,120"/><item title="上证50" cmd="cmd:2,114"/></item><item title="B股" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:101,7,14,1"><item title="沪深B股" cmd="cmd:101,7,14,1"/><item title="上证B股" cmd="cmd:101,1,14,1"/><item title="深证B股" cmd="cmd:101,3,14,1"/></item></item><item type =2><item title="板块" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:9,36,-1,0"><item title="概念板块" cmd="cmd:9,37,-1,0"/></item><item title="基金" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:66,9,14,1"><item title="沪深基金" cmd="cmd:66,9,14,1"/><item title="ETF基金" cmd="cmd:66,75,14,1"/></item></item>	<item type =2><item title="个股" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:60,6,14,1"><item title="科创板" cmd="cmd:60,74,14,1"/><item title="沪深300" cmd="cmd:2,119"/></item><item title="债券" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:102,8,14,1"><item title="可转债" cmd="cmd:102,28,14,1"/></item></item>	<item type =2><item title="综合排名" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:8,6"><item title="综合排名" cmd="cmd:8,6"/><item title="财务分析" cmd="cmd:62,6,50,1"/></item></item>	<item type =2><item title="市场热点" type=1 image="#926995" image_sel="#F7A1FF" image_hover="#F67EFF"  shortcut="SCRD" cmd="cmd:25"/><item title="行情异动" type=1 image="#926995" image_sel="#F7A1FF" image_hover="#F67EFF" shortcut="HQYD"  cmd="cmd:65"/></item></shortbar><web><url title="F10" web="http://basic.10jqka.com.cn/" open=0 ><p type="broker"/></url><url title="自选资讯"  web="https://cn/pc/#/index?active=3" id="73" /><url title="未来大事" web="https://-tt" id="74" /><url title="个股避雷" web="https://-tesan" id="77" /><url title="个股资讯" web="http://.1.1/hrhg/zxList"><p type="stock"/><p type="bzs"/><p type="skin"/></url><url title="研究报告" web="http://47..148.190/hrhg/yb"><p type="stock"/></url><url title="行业资讯" web="http://hrhg/blocklist"><p type="stock_hyblockcode"/><p type="stock_hyblockname"/></url><url title="payInfo" web="http://47:80/course/pay"></url><url title="SetDrawLine" web="http://16379/api/drawLines/set"><p type="phone"/><p type="plaform"/><p type="key"/></url><url title="webTest" web="https://win32/api/winuser/nc-winuser-wndproc" /><url title="今日最相似" web="http:49.:8880/klineRank" /><url title="commonShortcuts_jsp" web="web/.html" open=2/><url title="helpManual_mqt" web="web/.html" open=2/><url title="Register" web="http://16379/api/user/register?" open=0 ><p type="username"/><p type="phone"/><p type="code"/><p type="password"/><p type="confirmPassword"/><p type="inviteCode"/></url><special><!-- </zh> --><zh title="MACD" isMain="0"/><zh title="DMI" isMain="0"/><zh title="MTM" isMain="0"/><zh title="BOLL" isMain="0"/><zh title="PSY" isMain="0"/></special><fs_main><zh title="MA"/></fs_main><fs_sub><zh title="MACD"/><zh title="WR"/></fs_sub><kx_main><zh title="MA"/><zh title="MA2"/><zh title="BBIBOLL"/></kx_main><kx_sub><zh title="MACD"/><zh title="MTM"/><zh title="BOLL"/><zh title="PSY"/></kx_sub><vip_zb_rights><vip name="估值脉络线"  spell="GZMLX"/></vip_zb_rights><images></images><saveScheme save=1></saveScheme><tabBar hide=1></tabBar><skinVisible hide=0></skinVisible>
</config>

这篇关于java使用xstream框架生成xml文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/483448

相关文章

JVM 的类初始化机制

前言 当你在 Java 程序中new对象时,有没有考虑过 JVM 是如何把静态的字节码(byte code)转化为运行时对象的呢,这个问题看似简单,但清楚的同学相信也不会太多,这篇文章首先介绍 JVM 类初始化的机制,然后给出几个易出错的实例来分析,帮助大家更好理解这个知识点。 JVM 将字节码转化为运行时对象分为三个阶段,分别是:loading 、Linking、initialization

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

Spring Security--Architecture Overview

1 核心组件 这一节主要介绍一些在Spring Security中常见且核心的Java类,它们之间的依赖,构建起了整个框架。想要理解整个架构,最起码得对这些类眼熟。 1.1 SecurityContextHolder SecurityContextHolder用于存储安全上下文(security context)的信息。当前操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限…这些都被保

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Java架构师知识体认识

源码分析 常用设计模式 Proxy代理模式Factory工厂模式Singleton单例模式Delegate委派模式Strategy策略模式Prototype原型模式Template模板模式 Spring5 beans 接口实例化代理Bean操作 Context Ioc容器设计原理及高级特性Aop设计原理Factorybean与Beanfactory Transaction 声明式事物

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数