mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-09-03 05:24:28 +08:00
xml添加多层解析
This commit is contained in:
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
.idea
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-ali</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -232,10 +233,11 @@ public class XML {
|
||||
for (int idx = 0; idx < children.getLength(); ++idx) {
|
||||
Node node = children.item(idx);
|
||||
NodeList nodeList = node.getChildNodes();
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE && nodeList.getLength() <= 1) {
|
||||
m.put(node.getNodeName(), node.getTextContent());
|
||||
} else if (node.getNodeType() == Node.ELEMENT_NODE && nodeList.getLength() > 1) {
|
||||
int length = nodeList.getLength();
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE && length >= 1 && nodeList.item(0).hasChildNodes()) {
|
||||
m.put(node.getNodeName(), getChildren(nodeList));
|
||||
} else if (node.getNodeType() == Node.ELEMENT_NODE ) {
|
||||
m.put(node.getNodeName(), node.getTextContent());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -323,13 +325,47 @@ public class XML {
|
||||
value = "";
|
||||
}
|
||||
org.w3c.dom.Element filed = document.createElement(entry.getKey());
|
||||
if (value instanceof Map){
|
||||
/* if (value instanceof Map){
|
||||
map2Xml((Map)value, document, filed);
|
||||
}else if (value instanceof List){
|
||||
List vs = (List)value;
|
||||
for (Object v : vs ){
|
||||
if (value instanceof Map){
|
||||
map2Xml((Map)value, document, filed);
|
||||
}
|
||||
}
|
||||
map2Xml((Map)value, document, filed);
|
||||
}else {
|
||||
value = value.toString().trim();
|
||||
filed.appendChild(document.createTextNode(value.toString()));
|
||||
}
|
||||
}*/
|
||||
object2Xml(value, document, filed);
|
||||
element.appendChild(filed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void object2Xml(Object value, Document document, org.w3c.dom.Element element){
|
||||
|
||||
if (value instanceof Map){
|
||||
map2Xml((Map)value, document, element);
|
||||
}else if (value instanceof List){
|
||||
List vs = (List)value;
|
||||
for (Object v : vs ){
|
||||
object2Xml(v, document, element);
|
||||
}
|
||||
// map2Xml((Map)value, document, element);
|
||||
}else {
|
||||
value = value.toString().trim();
|
||||
element.appendChild(document.createTextNode(value.toString()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String text = "<data><code>0</code><users><user><id>1</id><name>张三</name></user><user><id>2</id><name>张4</name></user></users></data>";
|
||||
System.out.println( getMap2Xml(toJSONObject(text), "data", "utf-8"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>war</packaging>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-fuiou</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-payoneer</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-wx-youdian</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-wx</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
4
pom.xml
4
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>com.egzosn</groupId>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.12.9</version>
|
||||
<version>2.13.1-SNAPSHOT</version>
|
||||
|
||||
<name>Pay Java - Parent</name>
|
||||
<description>Pay Java Parent</description>
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
|
||||
<properties>
|
||||
<pay.version>2.12.9</pay.version>
|
||||
<pay.version>2.13.1-SNAPSHOT</pay.version>
|
||||
<httpmime.version>4.5.4</httpmime.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<fastjson.version>1.2.58</fastjson.version>
|
||||
|
||||
Reference in New Issue
Block a user