Skip to content

Commit

Permalink
Treat empty URL as the "default" namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
daemontus committed Oct 2, 2023
1 parent 1abd60b commit a936cd0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ impl Element {

/// Get namespace value given prefix, for this element.
/// "xml" and "xmlns" returns its default namespace.
///
/// This method can return an empty namespace, but only for an empty prefix assuming
/// there is no default namespace declared.
pub fn namespace_for_prefix<'a>(&self, doc: &'a Document, prefix: &str) -> Option<&'a str> {
match prefix {
"xml" => return Some("http://www.w3.org/XML/1998/namespace"),
Expand All @@ -400,7 +403,13 @@ impl Element {
if let Some(value) = data.namespace_decls.get(prefix) {
return Some(value);
}
elem = elem.parent(doc)?;
if let Some(parent) = elem.parent(doc) {
elem = parent;
} else if prefix.is_empty() {
return Some("");
} else {
return None;
}
}
}

Expand Down

0 comments on commit a936cd0

Please sign in to comment.