Created
December 10, 2020 11:20
-
-
Save sepastian/a68a62621a745adb203201d93e32599a to your computer and use it in GitHub Desktop.
Query XML attribute value by xpath using xmllint and ignoring namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See https://stackoverflow.com/questions/40796231/how-does-xpath-deal-with-xml-namespaces. | |
# To ignore namespaces use local-name(), for example: | |
# | |
# xmllint --xpath '//*[local-name()="structMap" and @TYPE="LOGICAL"]/*[local-name()="div"]/@TYPE' meta.xml | |
# Working example. | |
cat <<EOXML | xmllint --xpath '//*[local-name()="structMap" and @TYPE="LOGICAL"]/*[local-name()="div"]/@TYPE' - | |
<?xml version="1.0" encoding="UTF-8"?> | |
<mets:mets OBJID="" xsi:schemaLocation="http://www.loc.gov/standards/premis/ http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-7.xsd http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd http://www.loc.gov/standards/mix/ http://www.loc.gov/standards/mix/mix.xsd" xmlns:mets="http://www.loc.gov/METS/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mods="http://www.loc.gov/mods/v3" xmlns:goobi="http://meta.goobi.org/v1.5.1/"> | |
<mets:structMap TYPE="LOGICAL"> | |
<mets:div DMDID="DMDLOG_0000" ID="LOG_0000" TYPE="Manuscript"/> | |
</mets:structMap> | |
</mets:mets> | |
# TYPE="Manuscript" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment