xml: Add namespace deserialisation

This commit is contained in:
Lennart
2025-05-10 13:09:22 +02:00
parent 3af9b3b8b4
commit 37eb6df64a
3 changed files with 51 additions and 1 deletions

View File

@@ -342,3 +342,32 @@ fn test_struct_tuple() {
}
);
}
#[test]
fn test_struct_untagged_ns() {
#[derive(Debug, XmlDeserialize, XmlRootTag, PartialEq)]
#[xml(root = b"document")]
struct Document {
#[xml(ty = "untagged")]
child: Child,
}
#[derive(Debug, XmlDeserialize, PartialEq, Default)]
struct Child(
#[xml(ty = "tag_name")] String,
#[xml(ty = "namespace")] Option<String>,
);
let doc = Document::parse_str(
r#"
<?xml version="1.0" encoding="utf-8"?>
<document><test xmlns="hello" /></document>"#,
)
.unwrap();
assert_eq!(
doc,
Document {
child: Child("test".to_owned(), Some("hello".to_string()))
}
);
}