hbi99 / defiant.js

http://defiantjs.com
GNU Affero General Public License v3.0
913 stars 91 forks source link

Matching on elements with special characters #94

Closed brendon-stephens closed 6 years ago

brendon-stephens commented 6 years ago

Hi

Is it possible to match on element names with special characters, for example ':' and '$'. How would I extract the 'bk:title' and '$' elements?

Thanks!

{
   "store": {
      "book": [
         {
            "bk:title": "Sword of Honour",
            "category": "fiction",
            "author": "Evelyn Waugh",
            "$": 12.99
         },
         {
            "bk:title": "Moby Dick",
            "category": "fiction",
            "author": "Herman Melville",
            "isbn": "0-553-21311-3",
            "$": 8.99
         },
         {
            "bk:title": "Sayings of the Century",
            "category": "reference",
            "author": "Nigel Rees",
            "$": 8.95
         },
         {
            "bk:title": "The Lord of the Rings",
            "category": "fiction",
            "author": "J. R. R. Tolkien",
            "isbn": "0-395-19395-8",
            "$": 22.99
         }
      ],
      "bicycle": {
         "brand": "Cannondale",
         "color": "red",
         "$": 19.95
      }
   }
}
hbi99 commented 6 years ago

Hello @bstep93, Unfortunatly, you can not use ":" in the property, as you do for "bk:title".

Regarding elements of "$", you can query it like exemplified below. The first one matches on all elements where the key name is "$".

//*[@d:name="$"]

This second one will match on all, where the key name is "$" and its value is higher than "20".

//*[@d:name="$" and text() > 20]

I hope this helps...cheers