Simple .NET Core command-line tool for filtering XML files using XPath
- .NET CORE 3
> git clone https://github.com/nattfalk/xml-filter.git
> cd xml-filter
> dotnet build
xml-filter -i [input-file] -x [xpath-filter] [additional options]
-i, --input Required. Input XML file
-x, --xpath Required. XPath filter used to filter the elements
-o, --output Output XML file
-c, --contents Displays contents from given number of elements after applied filter
Apply filter and display number of filtered elements
> xml-filter -i testfiles\cd_catalog.xml -x /CATALOG/CD[COUNTRY='EU']
Results in
Filter resulted in 5 of totally 26 elements.
Apply filter and display contents of first 2 filtered elements
> xml-filter -i testfiles\cd_catalog.xml -x /CATALOG/CD[COUNTRY='EU'] -c 2
Results in
Filter resulted in 5 of totally 26 elements.
Displaying contents of 2 elements
---------------------------------
<CD>
<TITLE>Eros</TITLE>
<ARTIST>Eros Ramazzotti</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>BMG</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1997</YEAR>
</CD>
<CD>
<TITLE>Romanza</TITLE>
<ARTIST>Andrea Bocelli</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>Polydor</COMPANY>
<PRICE>10.80</PRICE>
<YEAR>1996</YEAR>
</CD>
Apply filter and save the filtered elements to file
> xml-filter -i testfiles\cd_catalog.xml -o result.xml -x /CATALOG/CD[COUNTRY='EU']
Results in
Filter resulted in 5 of totally 26 elements.
'test.xml' saved!
- Michael Nattfalk ([email protected])
This project is licensed under the MIT License - see the LICENSE file for details