In the example below, how do I access the attribute 'id' once it has a namespace prefix?
scala> val ns = <foo id="bar"></foo>
ns: scala.xml.Elem = <foo id="bar"></foo>
scala> ns \ "@id"
res15: scala.xml.NodeSeq = bar
Above works fine. According to the docs below should work but it doesn't.
scala> val ns = <foo xsi:id="bar"></foo>
ns: scala.xml.Elem = <foo xsi:id="bar"></foo>
scala> ns \ "@{xsi}id"
res16: scala.xml.NodeSeq = NodeSeq()
All on Scala 2.8.0.final
Cheers
Answer: It seems without an xlmns in the xml you can't access the attribute. So for the above example to work it needs to be inside an xlm namespace. e.g.:
scala> val xml = <parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <foo xsi:id="bar"></foo></parent>
xml: scala.xml.Elem = <parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <foo xsi:id="bar"></foo></parent>
scala> xml \ "foo" \ "@{http://www.w3.org/2001/XMLSchema-instance}id"
res3: scala.xml.NodeSeq = bar
ns \ "@{xsi}id"is not working :(