RReverser / serde-xml-rs

xml-rs based deserializer for Serde (compatible with 1.0+)
https://crates.io/crates/serde-xml-rs
MIT License
272 stars 90 forks source link

Custom { field: "missing field `soap:Body`" } when colon used #185

Open MrMarnic opened 2 years ago

MrMarnic commented 2 years ago

I am trying to decode this xml message: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><AuthenticateUserResponse xmlns="http://oneclickforapp.dpag.de/V3"><userToken>USERTOKEN</userToken><walletBalance>100000</walletBalance><showTermsAndConditions>true</showTermsAndConditions></AuthenticateUserResponse></soap:Body></soap:Envelope>

This is my code:

#[derive(Serialize,Deserialize)]
struct XMLEnvelope {
    #[serde(rename = "soap:Body")]
    pub body: XMLSoapBody
}
#[derive(Serialize,Deserialize)]
struct XMLSoapBody {
    #[serde(rename = "AuthenticateUserResponse")]
    pub response: XMLAuthenticateUserResponse
}
#[derive(Serialize,Deserialize)]
struct XMLAuthenticateUserResponse {
    pub userToken: String
}

But it results in this error: Err value: Custom { field: "missing field soap:Body" }'

If I change soap:Body to soapBody. (int the code and xml file). Then it works without a problem. The problem seems to be the colon (:).