How to query a XML file and save a subset using XPath
General
XML
- checks for a matching in an XML file
- copies a specific part for every match
- checks for a matching in an XML file
- copies a specific part for every match
Description :
# Select
xmlstarlet sel
# template <options> (-m, -c etc.)
--template
# match XPATH expression
--match "<XPath expression here>"
# print copy of XPATH expression
--copy-of "<XPath expression here>"
<file_to_query.xml>
Example :
xmlstarlet sel -t \
-m "/message:AIXMBasicMessage/message:hasMember/*[gml:identifier='d99f0949-81dc-46ca-bd9f-bb00fa613c3f']" \
-c "." \
"ED_Airspace_StrokedBorders_2024-12-26_2024-12-26_snapshot.xml" \
> d99f0949-81dc-46ca-bd9f-bb00fa613c3f.xml
2025 Jan