当标记中包含嵌入式标记时,如何将xml内容解析为js,如下面的 Source XML 所示。
我想解析<articletitle>
标记,但是目前xml2js解析器还读取内联标记,即; <em>
... </em>
和<strong>
... </strong>
。
源XML:
这是我的源XML片段:
<articletitle Language="En">Effects of enhanced UV-B radiation and drought stress on photosynthetic performance of lettuce(<em>Lactuca sativa</em><strong>Naghty</strong> L. romaine) plants</articletitle>
所需的JS输出:
当xml2js读取文章标题时,它应显示如下输出,从而内联标签应保持内联:
"artciletitle" : "Effects of enhanced UV-B radiation and drought stress on photosynthetic performance of lettuce(<em>Lactuca sativa</em><strong>Ranjitha</strong> L. romaine) plants"
有人可以建议如何实现吗?
编辑:
下面是我当前的node.js脚本:
var xml2js = require('xml2js');
var parseString = xml2js.parseString;
var xml = '<articletitle Language="En">Effects of enhanced UV-B radiation and drought stress on photosynthetic performance of lettuce(<em>Lactuca sativa</em><strong>Ranjitha</strong> L. romaine) plants</articletitle>'
var parseStringOpts = {
explicitArray: true,
explicitCharkey: true,
trim: true,
charkey: '#',
emptyTag: { "#": '' },
attrkey: '@',
preserveChildrenOrder: true,
mergeAttrs: false,
ignoreAttrs: false,
charsAsChildren: true,
explicitRoot: true
}
parseString(xml, parseStringOpts, (err, res) => {
if (err) console.log(err);
console.log('response', (JSON.stringify(res)));
response.status(200).send(JSON.stringify(res));
});