Skip to main content

I would like to extract the value "Version" or "version" (it differs from version to version :x ) from an XML. Usually I do this with a XMLFragmenter but XML is case sensitive so i need to do it twice and aggregate it. I think it can be done easier using XQuery but having a hard time to get it to work. So my questions are:

1. How to extract the value Version or version using XQuery from the next piece:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Leveringsinformatie xmlns="http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml/3.2">
<version>2.1</version>
</Leveringsinformatie>

2. How to learn XQuery?

Hi @nielsgerrits,

1. If one of <version> and <Version> always appears just once,  the XMLXQueryExtractor with this expression is a possible way:

declare default element namespace "http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418";
(data(//version), data(//Version))

2. I'm learning XQuery with these resources.

Note: the current XQuery processor 'Zorba' bundled with FME supports XQuery 3.0, so some functionality added in XQuery 3.1 can not be used yet.

Hope this helps.


Hi @nielsgerrits,

1. If one of <version> and <Version> always appears just once,  the XMLXQueryExtractor with this expression is a possible way:

declare default element namespace "http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418";
(data(//version), data(//Version))

2. I'm learning XQuery with these resources.

Note: the current XQuery processor 'Zorba' bundled with FME supports XQuery 3.0, so some functionality added in XQuery 3.1 can not be used yet.

Hope this helps.

Thanks for the fast response!

Hi @nielsgerrits,

1. If one of <version> and <Version> always appears just once,  the XMLXQueryExtractor with this expression is a possible way:

declare default element namespace "http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418";
(data(//version), data(//Version))

2. I'm learning XQuery with these resources.

Note: the current XQuery processor 'Zorba' bundled with FME supports XQuery 3.0, so some functionality added in XQuery 3.1 can not be used yet.

Hope this helps.

Variations:

 

declare default element namespace "http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418";
data(//version)||data(//Version)
declare default element namespace "http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418";
if (exists(//version)) then data(//version) else data(//Version)
declare default element namespace "http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418";
data(if (exists(//version)) then //version else //Version)
declare default element namespace "http://www.kadaster.nl/schemas/klic/leveringsinformatie/v20180418";
data(//*olocal-name()=('version', 'Version')])

 

'Zorba' also supports JSONiq which is an extension to manipulate JSON documents with XQuery expressions. However, there are only few resources to learn that. This is the only comprehensive documentation about JSONiq I found so far. If you found other good resources, please share them with us.

 


Reply