15 Matching Annotations
  1. May 2023
  2. Feb 2023
    1. <table><tbody><tr class="evn"><td> XPath </td><td> JSONPath </td><td> Description </td></tr> <tr class="odd"><td> / </td><td> $ </td><td class="lft">the root object/element </td></tr> <tr class="evn"><td> . </td><td> @ </td><td class="lft">the current object/element </td></tr> <tr class="odd"><td> / </td><td> . or [] </td><td class="lft">child operator </td></tr> <tr class="evn"><td> .. </td><td> n/a </td><td class="lft">parent operator </td></tr> <tr class="odd"><td> // </td><td> .. </td><td class="lft">recursive descent. JSONPath borrows this syntax from E4X. </td></tr> <tr class="evn"><td> * </td><td> * </td><td class="lft">wildcard. All objects/elements regardless their names. </td></tr> <tr class="odd"><td> @ </td><td> n/a </td><td class="lft">attribute access. JSON structures don't have attributes. </td></tr> <tr class="evn"><td> [] </td><td> [] </td><td class="lft">subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator. </td></tr> <tr class="odd"><td> | </td><td> [,] </td><td class="lft">Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set. </td></tr> <tr class="evn"><td> n/a </td><td> [start:end:step] </td><td class="lft">array slice operator borrowed from ES4. </td></tr> <tr class="odd"><td> [] </td><td> ?() </td><td class="lft">applies a filter (script) expression. </td></tr> <tr class="evn"><td> n/a </td><td> () </td><td class="lft">script expression, using the underlying script engine. </td></tr> <tr class="odd"><td> () </td><td> n/a </td><td class="lft">grouping in Xpath </td></tr></tbody></table>
  3. Sep 2022
  4. Jan 2022
    1. although if you are using XMLDOM with JavaScript you can code something like var n1 = uXmlDoc.selectSingleNode("//bookstore/book[1]/title/@lang"); and n1.text will give you the value "eng"
      • TEST, value: "selected".text
    2. @KorayTugay, No, the first expression selects, doesn't "return" -- a set of nodes, and this set of nodes is not a string. A node is not a string -- a node is a node in a tree. An XML document is a tree of nodes. lang="eng" is just one of many textual representations of an attribute node that has a name "lang", doesn't belong to a namespace, and has a string value the string "eng" – Dimitre Novatchev Oct 22 '14 at
      • OK: select, not value
    1. //Parent[@id='1']/Children/child/@name will only output the name attribute of the 4 child nodes belonging to the Parent specified by its predicate [@id=1]. You'll then need to change the predicate to [@id=2] to get the set of child nodes for the next Parent. However, if you ignore the Parent node altogether and use: //child/@name you can select name attribute of all child nodes in one go.
      • OK, select ALL
  5. Mar 2021
  6. Aug 2019
    1. Case in point: take this css selector: h1.header > a[rel~="author"] Its shortest functional XPath equivalent would be //h1[contains(" "+normalize-space(@class)+" "," header ")]/a[contains(" "+normalize-space(@rel)+" "," author ")] …which is both much harder to read and write. If you wrote this XPath instead: //h1[@class="header"]/a[@rel="author"] …you would incorrectly have missed markup like <h1 class="article header"><a rel="author external" href="/mike">...</a></h1>
    2. CSS syntax is awesome for two reasons: It is an order of magnitude faster and less resource intensive than the more complex XPath. When what you want to find can be found with a css selector, a corresponding XPath query doing the same would most of the time be much longer and harder to read.
  7. Apr 2016