-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore undeclared element when a $value field is present #596
Comments
Yes, for the sake of consistency it would be good to accept such XML. The problem only in construction of consistent rules that will not explode when combining. It is convenient to consider mapping of Rust types as definition of XSD types, which already has consistent rules. The presented type can be expressed in XSD at least by two definitions: <?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!--
Straightforward translation of `struct Root { ... }`.
Does not allow nested elements (because of
xs:simpleContent, required for extension of xs:string)
-->
<xs:complexType name="Root1">
<xs:simpleContent>
<xs:extension base="xs:string"/>
</xs:simpleContent>
</xs:complexType>
<!-- More permissive translation of `struct Root { ... }` -->
<xs:complexType name="Root2" mixed="true">
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:schema> This is incomplete definitions, because without I'm not sure, however, that this would be easy to add to quick-xml, because at deserializer side we don't know anything about So I leave this open if anyone wish to investigate this rabbit hole. |
Sometimes we need to get body accumulated to string, to deserialize later with different schema which version defined by attr <root version="01.04"
messageID="1"
messageName="SomeTag">
<SomeTag>
<OtherTag/>
</SomeTag>
</root> Where "SomeTag" should be readed as string with whole content #[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename = "root")]
pub struct Message {
#[serde(rename = "@version")]
pub version: String,
#[serde(rename = "@messageID")]
pub id: u32,
#[serde(rename = "@messageName")]
pub method: String,
#[serde(rename = "$value")]
pub body: T?,
} For example xmlserde has special struct Unparsed, but there another limitations
Any way to do that with quick-xml? |
I think, that what is you need here is a DOM node, that can be used as a type of I also have a plan to add basic DOM support to quick-xml itself and have a branch for that, but the work at the very beginning stage. My current goals are:
|
The default behaviour of ignoring XML elements that are not declared is very useful when dealing with XML that follows an extensible schema. However, including a
rename="$value"
field changes this behaviour, and undeclared elements generate an UnexpectedStart parse error.If the
rename = "$value"
is replaced byrename = "$text"
then the problem does not arise (parsing is successful and the Foo element is ignored). Is this the intended behaviour?The text was updated successfully, but these errors were encountered: