mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix XmlUtil
This commit is contained in:
parent
05aff7f94b
commit
83d3170942
@ -1600,8 +1600,8 @@ public class StrUtil {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int subLen = toIndex - fromIndex;
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final int subLen = toIndex - fromIndex;
|
||||
str.toString().codePoints().skip(fromIndex).limit(subLen).forEach(v -> sb.append(Character.toChars(v)));
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
@ -745,6 +746,7 @@ public class XmlUtil {
|
||||
if (false == isElement(childNode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
childEle = (Element) childNode;
|
||||
final Object value = result.get(childEle.getNodeName());
|
||||
Object newValue = null;
|
||||
@ -753,11 +755,14 @@ public class XmlUtil {
|
||||
final Map<String, Object> map = xmlToMap(childEle);
|
||||
if (MapUtil.isNotEmpty(map)) {
|
||||
newValue = map;
|
||||
} else{
|
||||
newValue = childEle.getTextContent();
|
||||
}
|
||||
} else {
|
||||
newValue = childEle.getTextContent();
|
||||
}
|
||||
|
||||
|
||||
if (null != newValue) {
|
||||
if (null != value) {
|
||||
if (value instanceof List) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import org.junit.Assert;
|
||||
@ -74,15 +75,18 @@ public class XmlUtilTest {
|
||||
+ "<remainpoint>1490</remainpoint>"//
|
||||
+ "<taskID>885</taskID>"//
|
||||
+ "<successCounts>1</successCounts>"//
|
||||
+ "<newNode><sub>subText</sub></newNode>"//
|
||||
+ "</returnsms>";
|
||||
Map<String, Object> map = XmlUtil.xmlToMap(xml);
|
||||
Console.log(map);
|
||||
|
||||
Assert.assertEquals(5, map.size());
|
||||
Assert.assertEquals(6, map.size());
|
||||
Assert.assertEquals("Success", map.get("returnstatus"));
|
||||
Assert.assertEquals("ok", map.get("message"));
|
||||
Assert.assertEquals("1490", map.get("remainpoint"));
|
||||
Assert.assertEquals("885", map.get("taskID"));
|
||||
Assert.assertEquals("1", map.get("successCounts"));
|
||||
Assert.assertEquals("subText", ((Map<?, ?>)map.get("newNode")).get("sub"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user