You Qi
You Qi

Reputation: 9211

How to convert XML to Array in XQuery?

Consider I have the following data:

let $fruits := <fruits>
    <fruit id="apple" />
    <fruit id="orange" />
</fruits>

how can I use the data in variable $fruits and parse it to become $fruits2 := ('apple', 'orange')?

I have fn:tokenize function in my mind but this only work with string. Thanks in advance for any helps.

Upvotes: 1

Views: 350

Answers (2)

adamretter
adamretter

Reputation: 3517

Just to clarify, there are no arrays in XQuery 1.0 and 3.0 only sequences. However, it is looking very likely at the moment that XQuery 3.1 will include an array type.

Upvotes: 0

Ewout Graswinckel
Ewout Graswinckel

Reputation: 1273

I think this is what you're looking for:

let $fruits2 := $fruits/fruit/@id/data()

Upvotes: 1

Related Questions