David Thielen
David Thielen

Reputation: 33006

XPath 3.1 reference that's complete & succinct

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?

Upvotes: 2

Views: 316

Answers (2)

Michael Kay
Michael Kay

Reputation: 163595

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.

Upvotes: 1

kjhughes
kjhughes

Reputation: 111726

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.

Upvotes: 3

Related Questions