Search code examples
xmlxpathxml-parsingxpath-2.0domxpath

Join child values via XPath?


I know my problem will be easily resolved if I have non-unique child nodes (by 'concat').

Problem:

<CarPlant>
      <Model>Audi</Model>
      <Model>Scoda</Model>
</CarPlant>

I would like to get a string e.g. "Audi,Scoda" to process it by scala's means.


Solution

  • This XPath 2.0 expression,

    /CarPlant/string-join(Model,',')
    

    will evaluate to

    Audi,Scoda
    

    for your XML, as requested.