Scala: XML Attribute parsing

后端 未结 4 1418
误落风尘
误落风尘 2021-01-02 02:02

I\'m trying to parse a rss feed that looks like this for the attribute \"date\":



    
        

        
4条回答
  •  星月不相逢
    2021-01-02 02:34

    Also, think about the difference between \ and \\. \\ looks for a descendent, not just a child, like this (note that it jumps from channel to c, without item):

    scala> (rssFeed \\ "channel" \\ "c" \ "@date").text
    res20: String = AA
    

    Or this sort of thing if you just want all the < c > elements, and don't care about their parents:

    scala> (rssFeed \\ "c" \ "@date").text            
    res24: String = AA
    

    And this specifies an exact path:

    scala> (rssFeed \ "channel" \ "item" \ "c" \ "@date").text
    res25: String = AA
    

提交回复
热议问题