mirror of
https://github.com/codehz/xmlio
synced 2026-01-14 03:11:32 +00:00
No description
| src | ||
| tests | ||
| .gitignore | ||
| README.md | ||
| xmlio.nimble | ||
XMLIO
Mapping nim type to xml node, use xaml-like semantics, <root name="123" /> equal to <root><root.name>123</root.name></root>.
Early development stage, break changes are expected!
Features
- Works with dynlib, can load new type from so/dll file, that's why I make this package (and vtable)
- Identify type by UUID, so it can be choosen manually to avoid conflict between dynlibs
- Use xmlns to avoid name conflict
Basic usage
DOCS: WIP (see tests for more examples)
- Import xmlio and xmlio/typeid_default
- Define your object type, only
string | SomeInteger | seq[T] | ref Tfield are supported (for now) - Register your type by using
generateXmlElementHandler, you need provide a UUID for it, and put verify code in body - Define the xmlns and xmlns registry instance
- Call
readXmlto parse xml - Done!
import xmlio, xmlio/typeid_default
type MyRoot = object of RootObj
name: string
secret: int32
generateXmlElementHandler MyRoot, "015a1611-9a98-4cb7-b77f-c7dc56b44507":
if self.name == "": raise newException(ValueError, "name should not be empty!")
if self.secret != 123: raise newException(ValueError, "secret is not matched")
var registry = newSimpleRegistry()
var rootns = newSimpleXmlnsHandler()
rootns.registerType("root", ref MyRoot)
registry["std"] = rootns
var root = readXml(registry, """<root xmlns="std" name="name"><root.secret>123</root.secret></root>""", ref MyRoot)
echo root.name # name
echo root.secret # 123