Skip to main content
Solved

Extract "Version" or "version" from XML.


nielsgerrits
VIP
Forum|alt.badge.img+54

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?

Best answer by takashi

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.

View original
Did this help you find an answer to your question?

3 replies

takashi
Evangelist
  • Best Answer
  • October 15, 2018

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.


nielsgerrits
VIP
Forum|alt.badge.img+54
takashi wrote:

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!

takashi
Evangelist
  • October 15, 2018
takashi wrote:

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(//versionelse 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(//*[local-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.

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings