|
| 1 | +# SyntaxTree::XML |
| 2 | + |
| 3 | +[](https://github.com/ruby-syntax-tree/syntax_tree-xml/actions/workflows/main.yml) |
| 4 | +[](https://rubygems.org/gems/syntax_tree-xml) |
| 5 | + |
| 6 | +[Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree) support for XML. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +Add this line to your application's Gemfile: |
| 11 | + |
| 12 | +```ruby |
| 13 | +gem "syntax_tree-xml" |
| 14 | +``` |
| 15 | + |
| 16 | +And then execute: |
| 17 | + |
| 18 | + $ bundle install |
| 19 | + |
| 20 | +Or install it yourself as: |
| 21 | + |
| 22 | + $ gem install syntax_tree-xml |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +From code: |
| 27 | + |
| 28 | +```ruby |
| 29 | +require "syntax_tree/xml" |
| 30 | + |
| 31 | +pp SyntaxTree::XML.parse(source) # print out the AST |
| 32 | +puts SyntaxTree::XML.format(source) # format the AST |
| 33 | +``` |
| 34 | + |
| 35 | +From the CLI: |
| 36 | + |
| 37 | +```sh |
| 38 | +$ stree ast --plugins=xml file.xml |
| 39 | +(document |
| 40 | + (misc "\n"), |
| 41 | + (element |
| 42 | + (opening_tag "<", "message", ">"), |
| 43 | + (char_data "\n" + " "), |
| 44 | + (element (opening_tag "<", "hello", ">"), (char_data "Hello"), (closing_tag "</", "hello", ">")), |
| 45 | + (char_data "\n" + " "), |
| 46 | + (element (opening_tag "<", "world", ">"), (char_data "World"), (closing_tag "</", "world", ">")), |
| 47 | + (char_data "\n"), |
| 48 | + (closing_tag "</", "message", ">") |
| 49 | + ) |
| 50 | +) |
| 51 | +``` |
| 52 | + |
| 53 | +or |
| 54 | + |
| 55 | +```sh |
| 56 | +$ stree format --plugins=xml file.xml |
| 57 | +<message> |
| 58 | + <hello>Hello</hello> |
| 59 | + <world>World</world> |
| 60 | +</message> |
| 61 | +``` |
| 62 | + |
| 63 | +or |
| 64 | + |
| 65 | +```sh |
| 66 | +$ stree write --plugins=xml file.xml |
| 67 | +file.xml 1ms |
| 68 | +``` |
| 69 | + |
| 70 | +## Development |
| 71 | + |
| 72 | +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. |
| 73 | + |
| 74 | +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
| 75 | + |
| 76 | +## Contributing |
| 77 | + |
| 78 | +Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-syntax-tree/syntax_tree-xml. |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
0 commit comments