Catmandu::Fix::xpath_map(3pm) | User Contributed Perl Documentation | Catmandu::Fix::xpath_map(3pm) |
Catmandu::Fix::xpath_map - map values from a XML::LibXML::Element value to a field
# <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'
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.
Map an XML field at "xml_field" to "new_field" using an XPath expresssion "xpath".
Catmandu::Fix
Patrick Hochstenbach , "patrick.hochstenbach at ugent.be"
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See <http://dev.perl.org/licenses/> for more information.
2022-11-29 | perl v5.36.0 |