Tuesday 16 May 2017

How to filter on child level and return parent node with JSONPath?

I want to get connector objects with specific type from a PowerPoint's XML file, which looks like this:

<p:cxnSp>
  .
  .
  .
  <p:spPr>
    <a:xfrm>
      <a:off y="4104000" x="1764000"/>
      <a:ext cy="936000" cx="4330800"/>
    </a:xfrm>
    <a:prstGeom prst="bentConnector3">
      <a:avLst/>
    </a:prstGeom>
  </p:spPr>
  .
  .
  .
</p:cxnSp>

The XML is parsed with xml2js node module. How can I filter with JSONPath by <a:prstGeom> tag's prst attribute, and return the whole p:cxnSp object?

As first step what I tried it looks like this:

JSONPath({ path: '$..p:cxnSp[?(@.p:spPr[?(@.a:prstGeom[?(@.prst === "bentConnector3")])])]', json: jsonData })

But I keep getting Unexpected token exception. Could be because of colons in tag names, or I just totally misunderstood the filter of JSONPath?



via Thookes

No comments:

Post a Comment