-
Notifications
You must be signed in to change notification settings - Fork 1
How to avoid deserializing certain XML elements (like HTML tags) and return as String. #6
Comments
If you look want to use serde (I think so because in your original question you use serde) it seems this is impossible now. Probably need a new attribute (actually a special field name, because we couldn't pass any attributes from struct to deserializer) which will instruct If you would use low-level events API, then you can mark |
Thank you for your precious time to answer my question. 👍 You can close this issue after merging the PR of the |
The original XML can be retrieved from the original string slice using "item" => {
let mut buf = Vec::new();
let start_position = reader.buffer_position();
// Non-standard labels may exist.
reader.check_end_names(false);
loop {
match reader.read_event(&mut buf) {
Ok(Event::End(ref e)) => match reader.decode(e.name()).unwrap() {
"item" => break,
_ => {}
},
Ok(Event::Eof) => break,
_ => {}
}
}
reader.check_end_names(true);
let end_position = reader.buffer_position();
let text_string = text.to_string();
// 7 is `</item>` length.
let item_slice = &text_string.as_bytes()[start_position..end_position - 7];
buf.clear();
console_log!("start: {}, end: {}", start_position, end_position - 7);
console_log!("{}", reader.decode(item_slice).unwrap());
} |
I think the correct way to handle this would to add a special method to the
|
The third variant -- add a method like: impl Reader {
// (signature approximate)
pub fn read_html(&self, end: &str, not_closed_tags: &[&str]) -> Result<BytesText> {
}
} It should consume all events until |
hum, If I'm reading something in non-standard XML format (such as HTML), I usually know about it in advance and turn off the closing check of the tag. |
Hi, mingun, Thank you for your work.
I want to skip the serialization of some child nodes in
fast_xml
and return them as strings.I didn't find this solution in
fast_xml
. What do I need to do?like description parse:
Similar questions: tafia/quick-xml#241
The text was updated successfully, but these errors were encountered: