Catman...th_map(3pm)
π Catmandu::Fix::xpath_map π
okay bestie, gather round, because this one is literally the fix you need when your XML is being extra π
Catmandu::Fix::xpath_map maps values from a XML::LibXML::Element value into a field. yes, that's the whole vibe. no cap. β¨
πΈ SYNOPSIS πΈ
# <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'
see how clean that is?? obsessed. the namespace mapping is the little cherry on top π
π¦ DESCRIPTION π¦
so here's the tea β: not every XML field in an XML Schema can just be mapped to a Perl Hash using Catmandu::XSD. especially those <any> fields in a schema β the ones that can hold literally any type of XML? yeah, those are the problem children π
those fields get mapped into a blessed XML::LibXML::Element object. and that's where the "xpath_map" Fix comes in, bestie β it lets you reach into those blessed objects and extract data from them using XPaths. main character energy fr fr π
π 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 expression xpath. that's it, that's the method π
π SEE ALSO π
Catmandu::Fix
π AUTHOR π
Patrick Hochstenbach , patrick.hochstenbach at ugent.be
β¨ LICENSE AND COPYRIGHT β¨
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.
and that's a wrap, angel π«Ά this lil page came to you via perl v5.36.0, dated 2022-11-29 β slay, iconic, no notes πβ¨
π¦ where this page comes from
- debian bookworm: libcatmandu-xsd-perl 0.05-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatmandu-xsd-perl 0.05-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms