Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devnote-dev/xmlt
XML (de)serializing with classes and structs
https://github.com/devnote-dev/xmlt
crystal crystal-lang xml xml-deserialization xml-serialization
Last synced: 16 days ago
JSON representation
XML (de)serializing with classes and structs
- Host: GitHub
- URL: https://github.com/devnote-dev/xmlt
- Owner: devnote-dev
- License: mit
- Created: 2022-04-01T18:08:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-19T13:14:22.000Z (7 months ago)
- Last Synced: 2024-05-06T00:04:59.455Z (6 months ago)
- Topics: crystal, crystal-lang, xml, xml-deserialization, xml-serialization
- Language: Crystal
- Homepage:
- Size: 73.2 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# XML Transformer
A library for serializing and deserializing XML documents with classes and structs. This follows the same includable syntax used in the standard library's JSON and YAML modules.## Installation
1. Add the dependency to your `shard.yml`:```yaml
dependencies:
xmlt:
github: devnote-dev/xmlt
```2. Run `shards install`
## Basic Usage
```crystal
require "xmlt"xml_str = %(123)
hash = Hash(String, Int32).from_xml xml_str, root: "Numbers"
puts hash # => {"one" => 1, "two" => 2, "three" => 3}puts hash.to_xml # => 123
```## Structured Usage
```crystal
require "xmlt"class Animal
# include the module so we can (de)serialize it
include XMLT::Serializableproperty name : String
@[XMT::Field(key: "species")]
property kind : String
@[XMLT::Field(omit_nil: true)]
property family : String?def initialize(@name, @kind, @family = nil)
end
endfox = Animal.new "fox", "mammal"
fox.to_xml # => mammalfox.family = "dog"
fox.to_xml # => mammaldog
```## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Devonte](https://github.com/devnote-dev) - creator and maintainerThis repository is managed under the MIT license.
© 2022 devnote-dev