node-xml2js
node-xml2js copied to clipboard
please add the current xml node param for attrNameProcessors and attrValueProcessors, tks
Hi
Thanks very much.
but when use this package to parse xml. I need to read the cureent xml node.
when I process the attrName and attrVlue use attrNameProcessors and attrValueProcessors.
but now is only name or value.
so please add the feature to next version.
thank very much
processName = function(processors, processedName,node)
processedKey = _this.options.attrNameProcessors ? processName(_this.options.attrNameProcessors, key,node) : key;
parseString(xml, {
tagNameProcessors: [tagNameProcessors],
attrNameProcessors: [attrNameProcessors],
valueProcessors: [valueProcessors],
attrValueProcessors: [attrValueProcessors]
}, function(err, result) {
})
function attrNameProcessors(name,node) {
}
@witwave What kind of value would you expect for the node
parameter?
Chiming in here 5 years later, I second this idea. If you had access to the node
inside the processor function, you could run the processor on specific nodes only, while skipping others.
Stupid example to illustrate the point:
<bookstore>
<book>
<price unit="cents" currency="USD">100</price>
<price unit="full" currency="USD>1</price>
<titleShouldBeLowercase>
<title>HARRY POTTER </title>
</titleShouldBeLowercase>
<titleShouldBeUppercase>
<title>harry potter </title>
</titleShouldBeUppercase>
</book>
</bookstore>
Goals:
- turn the value of the
<title>
element inside<titleShouldBeLowercase>...
into lowercase - turn the value of the
<title>
element inside<titleShouldBeUppercase>...
into uppercase - multiply the value of the
<price>
element with 100 if itsunit
attribute has the valuefull
Right now, as I only have access to the name
of an element, I cannot perform these processing steps since there is more than 1 element with the same name.
Maybe there are simpler ways to do identify a specific node inside the processor, without needing to pass full node
parameter to it, but it's the first thing that comes to mind as a solution.