嗨,
我正在尝试从此 XML Node/Elem 获取 attrID。
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
如果我手动删除命名空间,它工作得很好。
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)
我如何在不手动删除命名空间的情况下使其工作?