Skip to main content
Solved

Extract "Version" or "version" from XML.

  • October 15, 2018
  • 3 replies
  • 14 views

nielsgerrits
VIP
Forum|alt.badge.img+60

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

takashi
Celebrity
  • 7843 replies
  • 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+60
  • Author
  • 2940 replies
  • 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.

Thanks for the fast response!

takashi
Celebrity
  • 7843 replies
  • 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.

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