Skip to content
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

How to avoid deserializing certain XML elements (like HTML tags) and return as String #241

Closed
Zenleaf opened this issue Nov 7, 2020 · 1 comment
Labels
enhancement serde Issues related to mapping from Rust types to XML

Comments

@Zenleaf
Copy link

Zenleaf commented Nov 7, 2020

Hi there, I have the following XML that I would like to deserialize using Quick-Xml and Serde. It is part of a very large, nested XML structure.

<AbstractText Label="Results" NlmCategory="UNASSIGNED">
  We found that neonatal mortality was significantly associated with neonatal prematurity (p = 0.013), IUGR 
  <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML">
      <mml:mo>&lt;</mml:mo>
  </mml:math> 0.001), placental pathology (p = 0.04), we had no maternal mortality.
</AbstractText>

I want to deserialize the above into the following struct:

#[derive(Debug, Deserialize, PartialEq)]
pub struct AbstractText {
    #[serde(rename = "Label", default)]
    pub label: String,

    #[serde(rename = "NlmCategory", default)]
    pub nlm_category: String,

    #[serde(rename = "$value")]
    pub text: String,
}

As you can see the $value of <AbstractText> has some <mml:math> tags and occasionally will have some HTML tags.
I would like to have those tags deserialized to String. So "<mml:math>" must be stringiified as is.

How can I go about doing this? Currently I get Error: Start when trying to deserialize this.

@Zenleaf Zenleaf changed the title How to avoid deserializing certain xml elements and return as String How to avoid deserializing certain XML elements (like HTML tags) and return as String Nov 7, 2020
@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML labels May 21, 2022
@Mingun
Copy link
Collaborator

Mingun commented May 21, 2022

Duplicate of #383

@Mingun Mingun marked this as a duplicate of #383 May 21, 2022
@Mingun Mingun closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants