当前位置:网站首页>Elegantly spliced XML
Elegantly spliced XML
2022-06-12 06:54:00 【ldj2020】
package com.jt.dto;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* User: ldj
* Date: 2022/2/26
* Time: 20:30
* Description: No Description
*/
public class SpellXML {
public static void main(String[] args) {
// Analog interface parameters , From others
Map<String, Object> request = new HashMap();
request.put("Name2", " lily ");
request.put("Gender2", " Woman ");
request.put("Gender1", " male ");
StringBuilder builder = new StringBuilder();
builder.append("<Message>");
builder.append("\r\n");
builder.append("<School>");
builder.append("\r\n");
// Self defined Uncertain insertion sequence
Map<String, String> map1 = new HashMap<>();
map1.put("SchoolName", " Straw hat middle school ");
map1.put("SchoolId", "3333");
map1.put("SchoolAge", "100");
map1.forEach((k, v) -> {
builder.append(String.format("<%s>%s</%s>", k, v, k));
builder.append("\r\n");
});
builder.append("</School>");
builder.append("\r\n");
builder.append("<Class>");
builder.append("\r\n");
// Self defined Traverse in insertion order
Map<String, String> map2 = new LinkedHashMap<>();
map2.put("ClassName1", " three 7 class ");
map2.put("ClassName2", " three 9 class ");
map2.put("ClassName3", " three 3 class ");
map2.forEach((k, v) -> {
builder.append(String.format("<%s>%s</%s>", k, v, k));
builder.append("\r\n");
});
String name1 = (String) request.get("Name1");
String gender1 = (String) request.get("Gender1");
String name2 = (String) request.get("Name2");
String gender2 = (String) request.get("Gender2");
if (request.containsKey("Name1") || request.containsKey("Gender1")) {
builder.append("<Teacher>");
builder.append("\r\n");
if (StringUtils.isNotBlank(name1)) {
builder.append("<Name1>" + name1 + "</Name1>");
builder.append("\r\n");
}
if (StringUtils.isNotBlank(gender1)) {
builder.append("<Gender1>" + gender1 + "</Gender1>");
builder.append("\r\n");
}
builder.append("</Teacher>");
builder.append("\r\n");
}
if (request.containsKey("Name2") || request.containsKey("Gender2")) {
builder.append("<Student>");
builder.append("\r\n");
if (StringUtils.isNotBlank(name2)) {
builder.append("<Name2>" + name2 + "</Name2>");
builder.append("\r\n");
}
if (StringUtils.isNotBlank(gender2)) {
builder.append("<Gender2>" + gender2 + "</Gender2>");
builder.append("\r\n");
}
builder.append("</Student>");
builder.append("\r\n");
}
builder.append("</Class>");
builder.append("\r\n");
builder.append("</Message>");
System.out.println(builder.toString());
}
}


边栏推荐
- CL210OpenStack操作的故障排除--章節實驗
- Network packet loss troubleshooting
- Solution: content type 'application/x-www-form-urlencoded; charset=UTF-8‘ not supported
- The fifth day of June training - double pointer
- LeetCode-1303. Team size
- 六月集训 第八日——前缀和
- leetcode:剑指 Offer 63. 股票的最大利润【记录前缀最小和 or 无脑线段树】
- ConVIRT论文详解(医疗图片)
- Whether the modification of basic type and reference type is valid
- Tomato learning notes dvector and other basics
猜你喜欢

2021 RoboCom 世界机器人开发者大赛-本科组(初赛)

3 strings, containers, and arrays

Troubleshooting of cl210openstack operation -- Chapter experiment

Solution: content type 'application/x-www-form-urlencoded; charset=UTF-8‘ not supported

Solution: unsatisfieddependencyexception: error creating bean with name 'authaspect':

libprint2

Upload file (post form submission form data)

Codeforces Round #793 (Div. 2) A B C

Vscode Common plug - in

platform driver
随机推荐
When SQL server2019 is installed, the next step cannot be performed. How to solve this problem?
Dépannage de l'opération cl210openstack - chapitre expérience
XML special character escape
The difference between get and post and the code implementation of message board
Network packet loss troubleshooting
六月集训 第一日——数组
Set [list] to find out the subscript of repeated elements in the list (display the position of the subscript)
CL210OpenStack操作的故障排除--章節實驗
leetcode:剑指 Offer 67. 把字符串转换成整数【模拟 + 分割 +讨论】
leetcode:剑指 Offer 63. 股票的最大利润【记录前缀最小和 or 无脑线段树】
An error occurred while downloading the remote file The errormessage
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
(14) The software version number is displayed in the flash window of blender source code analysis
PHP read / write cookie
d的自动无垃集代码.
postman拼接替换参数循环调用接口
如何更新 Kubernetes 证书
【数据聚类】本专栏中涉及数据集、可视化及注意事项
SQL injection read / write file
六月集训 第五天——双指针