molily: getAttribute im IE spinnt

Beitrag lesen

Hallo,

javascript:alert(document.documentElement.getAttributeNS("http://www.w3.org/1999/xhtml","lang"))

Darauf bin ich auch hereingefallen. Das sollte funktionieren, denkt man - dummerweise ist genau das unmöglich:

»Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. ... The namespace name for an unprefixed attribute name always has no value.«
Namespaces in XML

Das heißt, wenn man <html xmlns="http://www.w3.org/1999/xhtml" lang="de"> schreibt, dann befindet sich »lang« NICHT im XHTML-Namespace! Man müsste vor alle Attribute ausdrücklich Präfixe vorsetzen, also z.B. <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xhtml:lang="de">. Erst dann ginge getAttributeNS("http://www.w3.org/1999/xhtml", …). Ansonsten muss man getAttributeNS("", …) nehmen. Damit ist getAttributeNS natürlich ziemlich unbrauchbar, weil man ja nicht weiß, wie die Attribute gerade im Code notiert sind. Man assoziert lang natürlich mit XHTML, aber die Standards tun es nicht - was ich für ziemlich panne halte.

Mathias