Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
[dependencies]
log = "0.4"
serde = "1.0"
xml-rs = "0.8"
xml = "1.0"
thiserror = "2.0"

[dev-dependencies]
Expand Down
9 changes: 9 additions & 0 deletions src/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,12 @@ let item = Item::deserialize(&mut Deserializer::new(event_reader)).unwrap();
assert_eq!(item, should_be);

```

# Supported Encodings

This crate relies on the `xml` crate for parsing XML.
It therefore supports the same encodings, namely:
- UTF-8 and UTF-16 (minimum requirement for the XML standard)
- The UTF-16 file must contain a byte-order mark
- ISO-8859-1
- ASCII
23 changes: 23 additions & 0 deletions tests/encodings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use rstest::rstest;
use serde::Deserialize;
use serde_xml_rs::from_reader;
use std::{fs::File, path::PathBuf};

#[derive(Debug, PartialEq, Deserialize)]
struct Document {
content: String,
}

#[rstest]
#[test_log::test]
fn given_supported_encoding_when_deserialize_then_ok(
#[files("tests/encodings/*.xml")] path: PathBuf,
) {
let expected = Document {
content: "abc".to_string(),
};
let file = File::open(path).unwrap();
let actual: Document = from_reader(file).unwrap();

assert_eq!(actual, expected);
}
4 changes: 4 additions & 0 deletions tests/encodings/ascii.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="ASCII"?>
<document>
<content>abc</content>
</document>
4 changes: 4 additions & 0 deletions tests/encodings/iso-8859-1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<content>abc</content>
</document>
Binary file added tests/encodings/utf-16.xml
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/encodings/utf-8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<content>abc</content>
</document>
1 change: 0 additions & 1 deletion tests/xml_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ fn given_method_reponse_when_deserialize_ok(
let file = File::open(path).unwrap();
let _value: MethodResponse = from_reader(file).unwrap();
}
//
Loading