From a199cc7b5c047fa3eab2357b1d79e6e138a666ae Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Wed, 3 Apr 2024 22:19:16 -0700 Subject: [PATCH] Map default xml prefix --- instant-xml/src/de.rs | 7 +++++++ instant-xml/tests/de-ns.rs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/instant-xml/src/de.rs b/instant-xml/src/de.rs index deb6e29..9952ddb 100644 --- a/instant-xml/src/de.rs +++ b/instant-xml/src/de.rs @@ -185,6 +185,13 @@ impl<'xml> Context<'xml> { } fn lookup(&self, prefix: &str) -> Option<&'xml str> { + // The prefix xml is by definition bound to the namespace + // name http://www.w3.org/XML/1998/namespace + // See https://www.w3.org/TR/xml-names/#ns-decl + if prefix == "xml" { + return Some("http://www.w3.org/XML/1998/namespace"); + } + self.stack .iter() .rev() diff --git a/instant-xml/tests/de-ns.rs b/instant-xml/tests/de-ns.rs index a49ecf5..7f11f4a 100644 --- a/instant-xml/tests/de-ns.rs +++ b/instant-xml/tests/de-ns.rs @@ -34,6 +34,12 @@ fn default_namespaces() { Ok(NestedDe { flag: true }) ); + // Default namespace not-nested - with xml:lang + assert_eq!( + from_str("true"), + Ok(NestedDe { flag: true }) + ); + // Default namespace not-nested - wrong namespace assert_eq!( from_str(