summaryrefslogtreecommitdiff
path: root/bs4/builder/_lxml.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2018-07-18 19:04:36 -0400
committerLeonard Richardson <leonardr@segfault.org>2018-07-18 19:04:36 -0400
commit68b55626839a8a0ea9e750fff546e201d144f96c (patch)
tree5a6acd307e3098dcaad17f4a930e48de09ba96ed /bs4/builder/_lxml.py
parent75c81928902b3f2896cbd3482a59828965627916 (diff)
Preserve XML namespaces when they are introduced inside an XML
document, not just the ones introduced at the top level. [bug=1718787]
Diffstat (limited to 'bs4/builder/_lxml.py')
-rw-r--r--bs4/builder/_lxml.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/bs4/builder/_lxml.py b/bs4/builder/_lxml.py
index 3439271..4a0f7de 100644
--- a/bs4/builder/_lxml.py
+++ b/bs4/builder/_lxml.py
@@ -151,11 +151,11 @@ class LXMLTreeBuilderForXML(TreeBuilder):
attrs = dict(attrs)
nsprefix = None
# Invert each namespace map as it comes in.
- if len(self.nsmaps) > 1:
- # There are no new namespaces for this tag, but
- # non-default namespaces are in play, so we need a
- # separate tag stack to know when they end.
- self.nsmaps.append(None)
+ if len(nsmap) == 0 and len(self.nsmaps) > 1:
+ # There are no new namespaces for this tag, but
+ # non-default namespaces are in play, so we need a
+ # separate tag stack to know when they end.
+ self.nsmaps.append(None)
elif len(nsmap) > 0:
# A new namespace mapping has come into play.
inverted_nsmap = dict((value, key) for key, value in nsmap.items())