Code Monkey home page Code Monkey logo

xml-filter's Introduction

xml-filter

Simple .NET Core command-line tool for filtering XML files using XPath

Prerequisites

  • .NET CORE 3

Installing

> git clone https://github.com/nattfalk/xml-filter.git
> cd xml-filter
> dotnet build

Usage

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

Examples

Example 1

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.

Example 2

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>

Example 3

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!

Authors

License

License

This project is licensed under the MIT License - see the LICENSE file for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.