dragonworx / jsel

DOM 3 XPath implementation for JavaScript object data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing object key from selector

oNaiPs opened this issue · comments

Thanks for such an awesome project! I'm trying to use this project to bring xpath capabilites to virtual-dom, so far it's working great!

I have an additional question, is it possible to directly access the key of a children attribute, namely myJsonData.children[0].foo.foo2 using a selector?

const jsel = require('jsel');

const myJsonData = {
  title: 'abc',
  children: [
    {
      foo: {
        foo2: 'bar',
      },
    },
    'val',
  ],
  subData: {
    foo: 555,
    foo2: 'bar2',
  },
};

const dom = jsel(myJsonData);

console.log(dom.select('//children/*[1]/??'));

Thanks a lot

Hi @oNaiPs you can access the foo2 attribute with either //children//@foo2 or //children/*[1]/foo/@foo2