diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-21 13:41:58 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-21 13:41:58 -0500 |
commit | 2b6af1e6204461e89338ae452c3bc742d0d1fa0f (patch) | |
tree | 01137ff6d0d0008607170b64fccf04cbaa504544 /bs4/element.py | |
parent | 2ccae07967bb15f6bad6ba262411ac47bcbb98e7 (diff) |
Have lxml invert namespace maps as they come in and set each tag's prefix appropriately.
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/bs4/element.py b/bs4/element.py index 73f225e..ab30951 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -805,6 +805,10 @@ class Tag(PageElement): else: closeTag = '</%s>' % self.name + prefix = '' + if self.nsprefix: + prefix = self.nsprefix + ":" + pretty_print = (indent_level is not None) if pretty_print: space = (' ' * (indent_level - 1)) @@ -825,7 +829,8 @@ class Tag(PageElement): attribute_string = ' ' + ' '.join(attrs) if pretty_print: s.append(space) - s.append('<%s%s%s>' % (self.name, attribute_string, close)) + s.append('<%s%s%s%s>' % ( + prefix, self.name, attribute_string, close)) if pretty_print: s.append("\n") s.append(contents) |