summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/bs4/element.py b/bs4/element.py
index 513407c..926fb8f 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -22,6 +22,20 @@ def _alias(attr):
return alias
+class NamespacedAttribute(object):
+
+ def __init__(self, namespace_abbreviation, name, namespace):
+ self.namespace_abbreviation = namespace_abbreviation
+ self.name = name
+ self.namespace = namespace
+
+ def __str__(self):
+ name = self.name
+ if self.namespace_abbreviation:
+ name = self.namespace_abbreviation + ":" + name
+ return name
+
+
class PageElement(object):
"""Contains the navigational information for some part of the page
(either a tag or a piece of text)"""
@@ -507,8 +521,8 @@ class Tag(PageElement):
"""Represents a found HTML tag with its attributes and contents."""
- def __init__(self, parser=None, builder=None, name=None, attrs=None,
- parent=None, previous=None):
+ def __init__(self, parser=None, builder=None, name=None, namespace=None,
+ attrs=None, parent=None, previous=None):
"Basic constructor."
if parser is None:
@@ -520,6 +534,7 @@ class Tag(PageElement):
if name is None:
raise ValueError("No value provided for new tag's name.")
self.name = name
+ self.namespace = namespace
if attrs is None:
attrs = {}
else:
@@ -779,7 +794,7 @@ class Tag(PageElement):
and '%SOUP-ENCODING%' in val):
val = self.substitute_encoding(val, eventual_encoding)
- decoded = (key + '='
+ decoded = (str(key) + '='
+ EntitySubstitution.substitute_xml(val, True))
attrs.append(decoded)
close = ''