50,348
社区成员




/*
<?xml version="1.0" encoding="UTF-8"?>
<root a="a" b="b" c="c" d="d"/>
*/
// 创建一个Document对象,将上面xml格式字符串转成Document
Document document = DocumentHelper.parseText(String str);
// 获取节点
Element root = document.getRootElement();
// 获取节点的属性
String a = root.attribute("a");
String b = root.attribute("b");
String c = root.attribute("c");
String d = root.attribute("d");
// 创建json对象
JSONObject json = new JSONObject();
json.put("a", a);
json.put("b", b);
json.put("c", c);
json.put("d", d);
以上代码没经过实际测试,只是给出一个大体写法,其中xml的操作使用的是DOM4J