Skip to content

namespace attributes in XML literals are reversed #12684

Open
@lrytz

Description

@lrytz

This one was always OK:

scala> <t a="1" b="2"/>
val res0: scala.xml.Elem = <t a="1" b="2"/>

This one was fixed in scala-xml 2.x (scala/scala-xml#172), the attributes are reversed when using 1.x:

scala> scala.xml.XML.loadString("""<t a="1" b="2"/>""")
val res1: scala.xml.Elem = <t a="1" b="2"/>

The fix also applies here:

scala> scala.xml.XML.loadString("""<t xmlns="xmlns-url" xmlns:xsd="xmlns-xsd-url"/>""")
val res0: scala.xml.Elem = <t xmlns="xmlns-url" xmlns:xsd="xmlns-xsd-url"/>

But for literals, namespace attributes are handled by the compiler and they are (and always were) reversed:

scala> <t xmlns="xmlns-url" xmlns:xsd="xmlns-xsd-url"/>

[[syntax trees at end of                    parser]] // <console>
...
        var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
        $tmpscope = new _root_.scala.xml.NamespaceBinding(null, "xmlns-url", $tmpscope);
        $tmpscope = new _root_.scala.xml.NamespaceBinding("xsd", "xmlns-xsd-url", $tmpscope);
        {
          val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
          new _root_.scala.xml.Elem(null, "t", _root_.scala.xml.Null, $scope, true)
        }
...
val res0: scala.xml.Elem = <t xmlns:xsd="xmlns-xsd-url" xmlns="xmlns-url"/>

scala> res0.scope
val res1: scala.xml.NamespaceBinding =  xmlns:xsd="xmlns-xsd-url" xmlns="xmlns-url"

scala> res0.scope.parent
val res2: scala.xml.NamespaceBinding =  xmlns="xmlns-url"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions