|
|
@@ -4,6 +4,7 @@
|
|
|
* @Author: vian
|
|
|
* @Date: 2020-09-09 10:45:54
|
|
|
*/
|
|
|
+const XML_RN_STR = '@-@';
|
|
|
const INTERFACE_EXPORT_BASE = (() => {
|
|
|
|
|
|
// xml字符实体
|
|
|
@@ -55,6 +56,9 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
}
|
|
|
cur = cur[field];
|
|
|
}
|
|
|
+ if (typeof cur === 'string') {
|
|
|
+ cur = cur.replace(new RegExp(XML_RN_STR, 'g'), '\r\n');
|
|
|
+ }
|
|
|
return cur || '';
|
|
|
}
|
|
|
|
|
|
@@ -579,6 +583,20 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
// x2js的str to json的实现方式基于DOMParser,DOMParser会自动将一些实体字符进行转换,比如 “< to <”。如果不想进行自动转换,需要进行处理。
|
|
|
xmlStr = escapeXMLEntity(xmlStr);
|
|
|
}
|
|
|
+
|
|
|
+ let reg1 = new RegExp('>\r\n', 'g');
|
|
|
+ xmlStr = xmlStr.replace(reg1, '>');
|
|
|
+
|
|
|
+ let reg2 = new RegExp('\r\n', 'g');
|
|
|
+ xmlStr = xmlStr.replace(reg2, XML_RN_STR);
|
|
|
+
|
|
|
+ // reg = /(?<=子目名称).+(?=单位)/g;
|
|
|
+ // let matchResult = xmlStr.match(reg);
|
|
|
+ // if (matchResult.length > 0) {
|
|
|
+ // console.log(matchResult[0]);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // xmlStr = xmlStr.replace(new RegExp('\r\n', 'g'), XML_RN_STR);
|
|
|
// 将xml格式良好的字符串转换成对象
|
|
|
const x2js = new X2JS();
|
|
|
let xmlObj = x2js.xml_str2json(xmlStr);
|