Skip to content

Instantly share code, notes, and snippets.

@lsloan
Last active January 20, 2016 17:00
Show Gist options
  • Save lsloan/0366b97e62e649aa5068 to your computer and use it in GitHub Desktop.
Save lsloan/0366b97e62e649aa5068 to your computer and use it in GitHub Desktop.

I've noticed when using DefiantJS's XPath features to search a list of Caliper event JSON from OpenLRS that it's necessary to use some special node names that aren't explcitly shown in the data. For example, if the JSON were:

[
    {
        "edApp": {
            "@id": "https://example.com/super-media-tool",
            "@type": "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
            "name": "Super Media Tool"
        }
    },
    {
        "navigatedFrom": {
            "@id": "https://example.edu/politicalScience/2015/american-revolution-101/index.html",
            "@type": "http://purl.imsglobal.org/caliper/v1/WebPage",
            "name": "American Revolution 101 Landing Page"
        },
        "edApp": {
            "@id": "https://example.com/viewer",
            "@type": "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
            "name": "Reader-O-Matic"
        }
    }
]

Note: This is valid JSON, but for the sake of brevity, they're not actually valid Caliper events, only fragments.

The whole list is called d:data and each Caliper event object is called d:item.

To select all events with a navigatedFrom attribute:

//d:item[navigatedFrom]

To select all events sent from the "Reader-O-Matic" application:

//d:item[edApp[name="Reader-O-Matic"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment