0

I am using lxml v4.4.1

When I parse a MathML document which use a namespace prefix (for instance xmlns:mml="http://www.w3.org/1998/Math/MathML"), element and attribute names are prefixed by "{http://www.w3.org/1998/Math/MathML}", which it normal.

example 1:

from lxml import etree

XML1 = """<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" mml:display="block"/>"""
math = etree.XML(XML1)
print(math.tag)
print(math.attrib)
# {http://www.w3.org/1998/Math/MathML}math
# {'{http://www.w3.org/1998/Math/MathML}display': 'block'}

But, when I use the default namespace (eg.: xmlns="http://www.w3.org/1998/Math/MathML"), attributes are not prefixed by the MathML namespace.

example 2:

XML2 = """<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"/>"""
math = etree.XML(XML2)
print(math.tag)
print(math.attrib)
# {http://www.w3.org/1998/Math/MathML}math
# {'display': 'block'}  # <-- WRONG

Is it a bug? How to work around that?

Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103
  • 1
    I don't think it is a bug. Default namespace declarations (no prefix) do not apply to attribute names. This means that attributes without a prefix are not in a namespace. See https://stackoverflow.com/q/41561/407651, http://www.rpbourret.com/xml/NamespaceMyths.htm#myth4. – mzjn Nov 20 '19 at 13:33
  • 1
    You are right! I have found the reference here : https://www.w3.org/TR/xml-names/#defaulting. It is really surprising. It says: **The namespace name for an unprefixed attribute name always has no value.**. – Laurent LAPORTE Nov 20 '19 at 13:49

0 Answers0