Reputation:
Hiho,
i'm trying to get the attrID from this XML Node/Elem.
scala> (desc(0) \ "_")(0)
res81: scala.xml.Node = <cor:attribute cor:attrDataType="int" cor:attrID="singleEventID" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cor="http://rdm.campusonline.at/">883819995</cor:attribute>
scala> (desc(0) \ "_")(0).attributes
res82: scala.xml.MetaData = cor:attrDataType="int" cor:attrID="singleEventID"
scala> (desc(0) \ "_")(0).attribute("cor:attrID")
res83: Option[Seq[scala.xml.Node]] = None
scala> (desc(0) \ "_")(0).attribute("""attrID""")
res85: Option[Seq[scala.xml.Node]] = None
If i remove the namespace manually, it works just fine.
scala> val test4 = <attribute attrDataType="int" attrID="singleEventID" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cor="http://rdm.campusonline.at/">883819995</attribute>
test4: scala.xml.Elem = <attribute attrID="singleEventID" attrDataType="int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cor="http://rdm.campusonline.at/">883819995</attribute>
scala> test4.attributes
res96: scala.xml.MetaData = attrID="singleEventID" attrDataType="int"
scala> test4.attribute("attrID")
res98: Option[Seq[scala.xml.Node]] = Some(singleEventID)
How i can make it work without manually removing the namespace?
Upvotes: 1
Views: 552
Reputation: 911
this solution will give you the attribute as a string
val CoreNs = http://rdm.campusonline.at
(desc(0) \ "_") \@ s"{$CoreNs}:attrID"
Upvotes: 1
Reputation: 11244
You need to use the other attribute
method like this
(desc(0) \ "_")(0).attribute("http://rdm.campusonline.at/", "attrID")
Upvotes: 2