node-xml2js
node-xml2js copied to clipboard
Empty string nodes
Is it possible to view empty string nodes, example name:" " , with tagNameProcessors, apparently I can not see them ?
It would probably be better to use attrValueProcessors
if you want to access attribute. For example, , the following demo which uses attrValueProcessors
can extract node1's name=""
const root = `
<xml>
<node1 name="">node text</node1>
<node2 name="node2">node2 text</node2>
</xml>
`;
const tagNameProcessor = function (name) {
console.log("node:", name);
return name;
}
const attrValueProcessor = function (value, name) {
console.log("name:", name, ",value:", value);
return value;
}
const parser = xml2js.Parser({ attrValueProcessors: [attrValueProcessor], tagNameProcessors: [tagNameProcessor] });
parser.parseString(root, function (err, result) {
if (err) {
console.error(err);
}
console.log(result);
});
the output of attrValueProcessor
are as followed:
name: name ,value:
name: name ,value: node2