XmlConvert
XmlConvert is a Ruby implementation of the .NET XmlConvert class. It encodes and decodes XML names, giving you an easy way to create NCName-compliant names from arbitrary strings.
Installation
Add this line to your application's Gemfile:
gem 'xml_convert'
And then execute:
$ bundle
Or install it yourself as:
$ gem install xml_convert
Usage
Encoding
Encode a name:
encoded_name = XmlConvert.encode_name("My Name") # "My_x0020_Name"
Encode a local name, escaping colons as well:
encoded_name = XmlConvert.encode_local_name("Foo: Bar") # "Foo_x003a__x0020_Bar"
Decoding
Any of the above Encoding examples can be reversed with XmlConvert.decode_name(name)
.
Contributing
- Fork it
- 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 new Pull Request