From 68b55626839a8a0ea9e750fff546e201d144f96c Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Wed, 18 Jul 2018 19:04:36 -0400 Subject: Preserve XML namespaces when they are introduced inside an XML document, not just the ones introduced at the top level. [bug=1718787] --- bs4/builder/_lxml.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bs4/builder/_lxml.py') 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()) -- cgit v1.2.3