let parser = new htmlparser.Parser({
ontext: function (text) {
if (text != null && text.trim() != "") {
_self.node.Value = text
onopentag: function (name, attribs) {
_self.node = {};
_self.node.Name = name;
_self.node.Attributes = attribs;
_self.stack.push(_self.node);
onclosetag: function (tagname) {
let pNode = _self.stack.pop();
if (_self.stack.length == 0) {
_self.rootName = pNode;
} else {
let parentNode = _self.stack[_self.stack.length - 1];
if (!parentNode.Childs) parentNode.Childs = [];
parentNode.Childs.push(pNode);
lowerCaseTags: false,
decodeEntities: true,
xmlMode: true
parser.write(_self.xml)
parser.end();
return _self.rootName
版权声明:本文为CSDN博主「qq_33761266」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:
https://blog.csdn.net/qq_33761266/article/details/102554095