Skip to content

Feature: Add support for opaque XmlValue, similar to JsonValue in serde_json. #115

Description

@valkum

Sometimes you need to interact with two systems speaking XML and you need to pass along some parts of an XML document. Currently, you need to implement complete support for de-/serializing of said types. Even if you do not intend to inspect said elements. This can be time consuming.
For these cases, it could be useful to have an opaque type that you can use, akin to serde_json::JsonValue. The simplest solution using just a String does not work because during serialization such strings get escaped.

Dynamic access to the elements/attributes/text in XmlValue is out of scope for this feature request.

This might also be hard in XML due to namespaces. If the opaque subtree of the document contains namespace prefix references, we need to make sure to emit these in a parent element during serialization.
I guess the type has to store all used namespaces (default and prefix) in child nodes, and during serialization, it needs to error if a namespace was not emitted in a parent (not on the namespace stack).

#[derive(FromXml, ToXml)]
struct Root {
 a: ElemA
 // This should use the field name. See https://github.com/djc/instant-xml/issues/83
 b: XmlValue
}

Struct ElemA {
...
}

Should allow you to read and emit:

<Root xmlns:some = "uri:some">
<ElemA>...<ElemA>
<b><SomeUnknownXmlTree><some:value>xxx</some:value>...</SomeUnknownXmlTree></b>

and also

<Root xmlns:some = "uri:some">
<ElemA>...<ElemA>
<some:b><some:UnknownXmlTree><some:value>xxx</some:value>...</some:UnknownXmlTree></b>

This is useful for Marks and SignedMarks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions