Skip to content

Instantly share code, notes, and snippets.

@michimau
Created July 23, 2019 14:28
Show Gist options
  • Select an option

  • Save michimau/e3103d3bee16b3a5f3c3198f930c35c5 to your computer and use it in GitHub Desktop.

Select an option

Save michimau/e3103d3bee16b3a5f3c3198f930c35c5 to your computer and use it in GitHub Desktop.
xpath for F
with ns as (
select ARRAY[ARRAY['xlink', 'http://www.w3.org/1999/xlink'], ARRAY['gmd', 'http://www.isotc211.org/2005/gmd'], ARRAY['gco', 'http://www.isotc211.org/2005/gco']] as n
)
SELECT uuid, changedate,
unnest(xpath('//gmd:identifier[*]/gmd:MD_Identifier[*]/gmd:code[*]/gco:CharacterString[1]/text()', XMLPARSE(DOCUMENT data), n)) as dataset_id,
changedate as datestamp,
unnest(xpath('//gmd:referenceSystemIdentifier[*]', XMLPARSE(DOCUMENT data), n)) as crs,
unnest(xpath('//gmd:citation[*]/gmd:CI_Citation[*]/gmd:title[*]/gco:CharacterString[1]/text()', XMLPARSE(DOCUMENT data), n)) as title,
--unnest(xpath('//gmd:edition[*]/gco:CharacterString[1]/text()', XMLPARSE(DOCUMENT data), n)) as edition,
unnest(xpath('//gmd:abstract[*]/gco:CharacterString[1]/text()', XMLPARSE(DOCUMENT data), n)) as abstract,
--unnest(xpath('//gmd:pointOfContact[*]/gmd:CI_ResponsibleParty[1]/gmd:role[*]/gmd:CI_RoleCode[@codeListValue="custodian"]', XMLPARSE(DOCUMENT data), n)) as custodian,
unnest(xpath('//gmd:onLine[*]/gmd:CI_OnlineResource[*]/gmd:protocol[*]/gco:CharacterString[1]/text()', XMLPARSE(DOCUMENT data), n)) as
protocol,
unnest(xpath('//gmd:onLine[*]/gmd:CI_OnlineResource[*]/gmd:linkage[*]/gmd:URL[1]/text()', XMLPARSE(DOCUMENT data), n)) path
FROM metadata, ns
WHERE isTemplate = 'n' AND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment