[英]Parsing XML elements without closing tags in JavaScript
I am running into a problem with the fast-xml-parser npm package.我遇到了快速 xml 解析器npm package 的问题。 I'm trying to parse some XML from an external source that has a series of elements with self closing tags but those elements have data in them that I need.
我正在尝试从外部源解析一些 XML,该外部源具有一系列带有自闭合标签的元素,但这些元素中包含我需要的数据。 Consider the following snippet:
考虑以下代码段:
const options = {
unpairedTags: ["link"]
};
const parser = new XMLParser(options);
const obj = parser.parse('<link something="idc" data="i care about this data"/>');
You can see that I have tried adding an unpaired tag but obviously this doesn't work because the idc
and data
properties are not considered XML so obj
still lands up being blank您可以看到我已经尝试添加一个未配对的标签,但显然这不起作用,因为不考虑
idc
和data
属性 XML 所以obj
仍然是空白
The default is to ignore attributes.默认是忽略属性。 Set the parse option
ignoreAttributes
设置解析选项
ignoreAttributes
const options = {
unpairedTags: ["link"],
ignoreAttributes : false
};
https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.