Deserialize xml with attributes

I'm working with serde_xml_rs and i have to parse this xml as follows:

<?xml version="1.0" encoding="ASCII"?>
<DeA_Configuration:Configuration xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:DeA_Configuration="http://www.xxx.com/DeA_Configuration">
 <info application="IMRS" physicalMonitorNumber="1" monitorWidth="900" monitorHeight="541"/>
<charToDrawMaskList>
    <charToDrawMask fileName="result/char/252.png" ascii="252"/>
    <charToDrawMask fileName="result/char/253.png" ascii="253"/>
    <charToDrawMask fileName="result/char/254.png" ascii="254"/>
  </charToDrawMaskList>
  </DeA_Configuration:Configuration>

Unfortunately i found only cases with no argument in the explanation about this crate.
I tried to create my struct:

#[derive(Debug, Deserialize, PartialEq)]
 struct Data{ 
    #[serde(rename = "DeA_Configuration:Configuration")]
    group: Vec<charToDrawMaskList>
    //#[serde(rename = "widthSymbol")]
}

#[derive(Debug, Deserialize, PartialEq)]
 struct charToDrawMaskList{ 
    filename: String,
    ascii: String,

But it returns me:
missing field DeA_Configuration:Configuration".
How should i create the struct to parse correctly this xml?

<DeA_Configuration:Configuration> is already the root element, so we don't need to specify it again as the field name.

#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
struct Configuration {
    info: Info,
    char_to_draw_mask_list: CharToDrawMaskList,
}

#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
struct Info {
    application: String,
    physical_monitor_number: u64,
    monitor_width: u64,
    monitor_height: u64,
}

#[derive(Debug, Deserialize, PartialEq)]
struct CharToDrawMaskList {
    #[serde(rename = "charToDrawMask")]
    items: Vec<CharToDrawMask>,
}

#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
struct CharToDrawMask {
    file_name: String,
    ascii: u8,
}
3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.