https://github.com/brunoarueira/validates_xml_of
Validates if an attribute has a valid xml content or a xsd valid content
https://github.com/brunoarueira/validates_xml_of
schema xml xsd
Last synced: about 1 year ago
JSON representation
Validates if an attribute has a valid xml content or a xsd valid content
- Host: GitHub
- URL: https://github.com/brunoarueira/validates_xml_of
- Owner: brunoarueira
- License: mit
- Created: 2016-03-15T13:39:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-04-17T18:20:55.000Z (about 4 years ago)
- Last Synced: 2025-05-01T08:17:25.782Z (about 1 year ago)
- Topics: schema, xml, xsd
- Language: Ruby
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ValidatesXmlOf
[](https://travis-ci.org/brunoarueira/validates_xml_of)
[](https://codeclimate.com/github/brunoarueira/validates_xml_of)
[](https://codeclimate.com/github/brunoarueira/validates_xml_of/coverage)
Validates if a given string contains a valid xml and validates based on defined
schema too.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'validates_xml_of'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install validates_xml_of
## Usage
### Rails
If you do not want to use xsd:
```
class Post < ActiveRecord::Base
...
validates :content, xml: true
...
end
```
And if you want to use xsd, you will need to define an initializer to setup a path for your schemas:
```
ValidatesXmlOf.setup do |config|
config.schema_paths = "lib/xsds"
end
```
After, you need to set your validation to specify what schema you are looking for:
```
class Post < ActiveRecord::Base
...
# The schema must be in lib/xsds/Schema.xsd
validates :content, xml: { schema: 'Schema' }
...
end
```
***PS:*** Coming soon, I will implement a generator to create this initializer
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/brunoarueira/validates_xml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).