xml - Simple Xpath query in scala -


i'm trying run xpath query scala , doesn't seem work. xml looks ( simplified):

<application>   <process type="output" size ="23">       <channel offset="0"/>       ....      <channel offset="4"/>   </process>   <process type="input" size ="16">       <channel offset="20"/>       ....      <channel offset="24"/>   </process> </application> 

i want retrieve process input attribute , use xpath query:

//process[@type='input'] 

this should work, verified xpathtester now, scala code looks like:

import scala.xml._ val x = xml.loadfile("file.xml")  val process = (x \\ "process[@type='input']")  // return empty nodeseq() !!! 

the process ends empty, does't capture want. worked around this:

val process = (x \\ "process" filter( _ \"@type" contains text("input"))) 

which uglier. known reason why original query shouldn't work?

"xpath" should not used describe scala standard library supports. xpath full-fledged expression language, far 2 final versions , third in works:

at best scala has small subset of xpath-inspired operations. can't expect take xpath expressions , directly paste them scala without doing bit more work.

third-party libraries can give better support actual xpath expressions, including:

  • scales xml
    • scala library
    • "provides far more xpath experience normal scala xml, paths xpaths , work them (with many of same functions , axes)"
    • it's still not actual xpath if understand well
    • designed integrate scala
  • saxon
    • java library
    • open source
    • complete , conformant support xpath 2 (and xslt 2)
    • has xpath api works on dom , other data models, no specific scala support @ time

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -