strong-xml icon indicating copy to clipboard operation
strong-xml copied to clipboard

Namespaces MVP

Open TheSchemm opened this issue 3 years ago • 0 comments

This is a pretty simple implementation of namespaces. Fixes #22.

Example Usage:

#[derive(XmlWrite, XmlRead, PartialEq, Debug)]
#[xml(tag = "n:nested", ns = "n: http://www.example.com")]
struct Nested {
    #[xml(child = "n:nested")]
    contents: Vec<Nested>,
}

Note the space between n: and http://www.example.com. Using the default namespace would just be: #[xml(tag = "nested", ns = "http://www.example.com")]

Features:

  • Fully backward compatible implementation; all original tests pass.
  • It serializes missing namespaces that are used by nested structs when the child element is written.
  • Implemented so that static validation would be easier to write, as namespaces have to be kept track of while writing.

Todos:

  • Does not validate yet.
  • Some additional refactoring can (should) be done around how prefixes and how namespaces are kept track of
  • Currently can only declare namespaces at the type level. Adding support for namespaces on nested types wouldn't be difficult.

TheSchemm avatar May 16 '22 21:05 TheSchemm