xml2js解析器忽略数组中的空字符串,从而导致数组大小更改

时间:2017-04-27 14:49:48

标签: node.js typescript xml2js

下面的xml要解析:

<ENVELOPE>
<ABC>
    <DEF>apple</DEF>
    <GHI>4</GHI>
    <JKL>85</JKL>
</ABC>
<MNO>add</MNO>
<PQR></PQR>
<STU></STU>
</ENVELOPE>
解析后的

和响应:

{

“ENVELOPE”:{     “ABC”:{       “DEF”:“苹果”,       “GHI”:“4”,       “JKL”:“85”     },     “MNO”:“添加”   }     }

xml2js解析已丢弃其他两个标记。但我需要它至少是空的。尝试过使用解析器的选项但没有运气

以下是获取解析器的代码:

private getParser() {
let nameToLowerCase = (name: string): string => {
  return name.toLowerCase();
}

let options: xml2js.Options = {
  attrkey: '_',
  charkey: '$',
  explicitCharkey: true,
  emptyTag: null,
  normalize: true,
  normalizeTags: true,
  explicitArray: false,
  trim: true,
  tagNameProcessors: [nameToLowerCase],
  attrNameProcessors: [nameToLowerCase]
};

return new xml2js.Parser(options);

}

0 个答案:

没有答案