Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.87k stars 601 forks source link

Ability to parse relative XPath references #586

Open jadfls opened 3 years ago

jadfls commented 3 years ago

Hi,

I have xml files that include reference attributes using XPath to reference other elements. Example:

<order>
  <product>
    <id>product_001</id>
  </product>
  <product>
    <id>product_002</id>
  </product>
  <product reference="../product[2]"/>
  <order reference=".."/>
</order>

Is there a way to resolve these XPath attributes?

Or is there a way to utilize XPath when I use custom attrValueProcessors?

attrValueProcessors: [function (value, name){
            if(name == "reference") {
                console.log("attrValueProcessors: "+name+" "+value);
                //use node-xml2js-xpath to extract the information which is referenced by value?
            }
            return value;
        }],