mixml
Mixml is a small tool to greatly simplify the tedious task of changing multiple XML files at once. Its main purpose is to spare me from having to use XSLT ever again.
Usage
You can use mixml to change XML files in the following ways:
- Pretty print
- Print selected nodes and attributes to the console
- Remove nodes
- Add nodes
- Replace nodes
- Rename nodes
- Change node values
For example, the following command will remove all attributes named id
from the all XML files in the current
directory.
mixml remove --inplace --xpath '//@id' *.xml
The following command will pretty print all XML files:
mixml pretty --inplace *.xml
The following command will print all attribute names and values:
mixml write --xpath '//@*' --template '{=node.name}={=node.value}' test.xml
You can find a description of all supported commands and usage examples here.
Selection
In addition to using XPath expressions, you can also use CSS rules to select the nodes you want to process. For example, the following command will remove the first child of each element:
mixml remove --inplace --css '*:first-child' *.xml
You can find a detailed description and usage examples here.
Scripts
In addition to the command line, mixml also supports a simple simple DSL to perform scripted changes. For example, to
perform the same as above using a script, save the following in test.mixml
:
xpath '//@id' do
remove
end
and then call:
mixml execute --script test.mixml *.xml
You can also use mixml directly in your Ruby code. See here for usage examples.
Values
Mixml supports specifying XML fragments that are to be inserted using
See here for a description of all methods and detailed usage examples.
Output
XML output can be printed to the console or written back to the file it was read from. Mixml also supports pretty printing all output. See here for a detailed description and usage examples.
Installation
Install mixml:
$ gem install mixml
Contributing
- Fork the GitHub repository: https://github.com/jochenseeber/mixml/fork
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Create a new Pull Request