listmap转xml
| |
| import org.jdom2.Element; |
| import org.jdom2.Document; |
| import org.jdom2.output.Format; |
| import org.jdom2.output.XMLOutputter; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public static String listToXmlString(List<Map> list) throws IOException { |
| Document result = new Document(); |
| |
| Element root = new Element("DATASETS"); |
| root.setText(""); |
| if (list != null) { |
| for (Map map : list) { |
| Set keys = map.keySet(); |
| Iterator iterator = keys.iterator(); |
| |
| Element data = new Element("DATASET"); |
| while (iterator.hasNext()) { |
| String key = String.valueOf(iterator.next()); |
| String value = String.valueOf(map.get(key)); |
| Element node = new Element(key); |
| node.setText(value); |
| data.addContent(node); |
| } |
| root.addContent(data); |
| } |
| } |
| ArrayList arrayList = new ArrayList(); |
| arrayList.add(root); |
| result.setContent(arrayList); |
| String resultXML = docToXml(result); |
| return resultXML; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public static String docToXml(org.jdom2.Document doc) throws IOException { |
| Format format = Format.getPrettyFormat(); |
| format.setEncoding("UTF-8"); |
| XMLOutputter xmlout = new XMLOutputter(format); |
| ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
| |
| xmlout.output(doc, bo); |
| String xmlStr = bo.toString(); |
| return xmlStr; |
| } |
原list数据
| [ |
| { |
| education=undergraduate, |
| occupation=programmer, |
| name=范闲, |
| weight=150, |
| age=23, |
| height=173, |
| hobby=basketball |
| }, |
| { |
| education=undergraduate, |
| occupation=programmer, |
| name=王一, |
| weight=120, |
| age=22, |
| height=168, |
| hobby=game |
| }, |
| { |
| education=undergraduate, |
| occupation=programmer, |
| name=魏胖, |
| weight=125, |
| age=22, |
| height=170, |
| hobby=novel |
| } |
| ] |
转化成的xml文件
| <?xml version="1.0" encoding="UTF-8"?> |
| <DATASETS> |
| <DATASET> |
| <education>undergraduate</education> |
| <occupation>programmer</occupation> |
| <name>范闲</name> |
| <weight>150</weight> |
| <age>23</age> |
| <height>173</height> |
| <hobby>basketball</hobby> |
| </DATASET> |
| <DATASET> |
| <education>undergraduate</education> |
| <occupation>programmer</occupation> |
| <name>王一</name> |
| <weight>120</weight> |
| <age>22</age> |
| <height>168</height> |
| <hobby>game</hobby> |
| </DATASET> |
| <DATASET> |
| <education>undergraduate</education> |
| <occupation>programmer</occupation> |
| <name>魏胖</name> |
| <weight>125</weight> |
| <age>22</age> |
| <height>170</height> |
| <hobby>novel</hobby> |
| </DATASET> |
| </DATASETS> |
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现