2

I've been reading through the W3 spec for XPath 3.1, and it's way too long for most to read (they'll just quit). Is there an abbreviated specification anywhere?

Our audience is users of our system that need to write an XPath statement to pull back the data they need. They are not programmers, they are business users. And they want to find a solution to their specific need as quickly as possible when they get stuck.

Update: First off, I totally agree with @kjhughes comment below "intrinsic tension". And I think Michael brings up a good point that the quick guide should be the main use - remove the edge cases. And reduce notes to a minimum (again no edge cases), but yes to examples.

What we have used for years is this tutorial, it tends to have a good balance between simplicity and teach all the basics. And this one is not bad.

But neither discusses either XPath 3.1 or crafting XPath for a JSON file. Is there anything equivalent out there.

As an example, here's three basic items I'm still struggling with:

  1. What's the syntax for a basic query. Using Southwind.json is it "/Employees/Employee" to get a list of all the employee nodes (I can't successfully load a JSON file in my code yet so I can't test this)?
  2. Are maps ever returned from an XPath query/evaluate? From reading this it looks like you can create and use them, but you don't ever get them as a returned item for a query.
  3. Are arrays only returned on queries of JSON? From reading this, I think that is the case. And this just maps to a JSON array - correct?
David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • 1
    There are two ways you can write a shorter spec. You can take out discussions of edge cases, which will make it succinct but incomplete, or you can take out a lot of the notes and examples, which will make it succinct, complete, and unreadable, – Michael Kay Jul 16 '20 at 23:25
  • @MichaelKay I agree. I expanded on my query above based on your & kjhughes' comment/answer. thanks – David Thielen Jul 17 '20 at 15:43

2 Answers2

2

There's an intrinsic tension between complete & succinct.

For complete, there's no substitute for the official specification: XML Path Language (XPath) 3.1. If it seems too extensive for your needs, you're simply not the intended audience. We want language implementers to have a complete, precise standard specification against which to build libraries and tools. It's the whole point of having a specification.

For succinct, you'll necessarily sacrifice completeness, but here are some resources that might fit the bill as overviews or introductions:


Update per question update:

Our audience is users of our system that need to write an XPath statement to pull back the data they need. They are not programmers, they are business users. And they want to find a solution to their specific need as quickly as possible when they get stuck.

Business users ought to have a proper, application-specific GUI, not be expected to write raw XPaths or regex or SQL.

If you insist that your business users write XPaths, and if they're at least technically sophisticated, then your best bet would be to write casebook containing commonly used idioms and examples from which they can try to learn. Supplement with a presentation on XPath fundamentals.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I added some more info around this. And I may be over-thinking this. If for basic & medium complex queries all that's changed is the array type for JSON results, there's not much new to add to the XPath 2.0 tutorials. thanks. – David Thielen Jul 17 '20 at 15:42
1

The basic trouble is that XPath has become quite a big language, and the more concise the reference you construct, the less likely it is to contain the answer to every question you want to ask. For your specific questions:

What's the syntax for a basic query. Using Southwind.json is it "/Employees/Employee"

I'm not familiar with the dataset.

Are maps ever returned from an XPath query/evaluate?

Of course. The simplest query that returns a map is map{}.

Are arrays only returned on queries of JSON?

No. For example the query [1, 2, 3] returns an array, and there's no JSON involved.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • 1
    Is there some getting started tutorial for using XPath to query JSON? The W3C spec is not a good way to learn how to craft a query. – David Thielen Jul 17 '20 at 21:06