Catmandu::Fix::xpath_map(3pm)

Catmandu::Fix::xpath_map3pm

Map values from a xml::libxml::element value to a field

Usage

   #   <mets:dmdSec ID="dmd1">
   #    <mets:mdWrap MDTYPE="MODS">
   #     <mets:xmlData>
   #      <mods:mods xmlns:mods="http://www.loc.gov/mods/v3" ID="mods1" version="3.4">
   #        <mods:titleInfo>
   #         <mods:title>Alabama blues</mods:title>
   #        </mods:titleInfo>
   #      </mods:mods>
   #     </mets:xmlData>
   #    </mets:mdWrap>
   #   </mets:dmdSec>
   # The dmdSec.0.mdWrap.xmlData contains a XML::LibXML::Element
   # Map the value of the 'mods:titleInfo/mods:title' XPath to
   # a new field 'my_new_field'.
   # Optionally provide one or more namespace mappings to use
   xpath_map(
       dmdSec.0.mdWrap.xmlData,
       'mods:titleInfo/mods:title',
       my_new_field,
       -mods:'http://www.loc.gov/mods/v3'
   )
   # Result:
   #
   # 'my_new_field' => 'Alabama blues'

Overview

Not all XML fields in an XML Schema can be mapped to a Perl Hash using Catmandu::XSD. Especially <any> fields in a schema, which can contain any type of XML are problematic. These fields are mapped into a blessed XML::LibXML::Element object. Using the "xpath_map" Fix, on can access these blessed objects and extract data from it using XPaths.

Method

xpath_map(xml_field, xpath, new_field [, namespace-prefix:namespace-url [,...]])

Map an XML field at "xml_field" to "new_field" using an XPath expresssion "xpath".

Releases

4 releases since Debian 10 (Buster); the text changed 3 times.

  1. 10
  2. 11
  3. 12
  4. 13

Author

Patrick Hochstenbach , "patrick.hochstenbach at ugent.be"

From libcatmandu-xsd-perl 0.05-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.