XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] XPath 3.1 introduction ?

Hi Christophe

The most prominent add to XPath 3.1 is maps and arrays.

Here's a very abstract overview (which of course misses plenty of smaller details). It also applies to XQuery 3.1, which supports them as well.

In short:
========
- Items in sequences can now also be maps or arrays.
- Maps are associative arrays. Keys are any atomic value. Values are any sequences of items (including arrays and maps, so they can nest).
- Arrays are ordered lists of values. A values is any sequence of items (including arrays and maps, so they can nest).
- Values put into maps and arrays are *not* copied, so you can use maps, say, for indexing. This is different from XML node constructors.

To build them:
========
- One syntax for objects, looking a bit like JSON but more generic (since you can of course nest expressions) and with a keyword "map", like node constructors:

map { "foo" : "bar", "bar" : (1, 2, 3) }

- Two syntaxes for arrays:

Syntax 1 similar to that of maps, with an "array" keyword. It simply takes the sequence and each item in it becomes a value of the array (So you can't construct arrays with sequences of more than one item with this one):
array { 1, (2, 3, 4), (), 5 }
creates an array with 5 values, 1, 2, 3, 4 and 5.

Syntax 2 similar to JSON, but it's comma-sensitive in the sense that they delimit the values (so it's not a comma expression inside: the commas are part of the constructor)
[ 1, 2, 3, 4, (), (5, 6) ]
creates an array with 5 values : 1, 2, 3, 4, the empty sequence, and the sequence (5,6)

Navigation:
========
Alternative 1: Use maps and arrays as function items:
let $map := map { "foo" : "bar" }
return $map("foo")

let $array := array { 1, 2, 3 }
return $array(2)

Alternative 2: Use the ? operator (for NCNames and integers):
let $map := map { "foo" : "bar" }
return $map?foo

let $array := array { 1, 2, 3 }
return $array?2

The ? operator works with wildcards to "unbox" arrays or maps to a sequence:
let $array := array { 1, 2, 3 }
return $array?*

(it also exists as a unary operator, which implicitly assumes the context item on the left-hand-side)

Functions:
========
There are plenty of new functions for maps and arrays documented here: https://www.w3.org/TR/xpath-functions-31/#maps-and-arrays

Types:
=======
There are item type notations such as map(*), map(xs:integer, node()), array(xs:integer), array(*), etc.

I hope it helps you get started!

Feel free to correct me if I got anything wrong in the above.

Kind regards,
Ghislain



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS