1
0
-1

I am trying to parse an XML document that includes namespaces using the XmlDoc class in fluent, but I can't figure out what XPath to use when referring to elements that have a namespace defined:

import com.avoka.tm.util.*
String startXml = """<ns1:root ns1='www.google.com'>
<ns1:data1>test</ns1:data1>
<data2>test</data2>
</ns1:root>"""
XmlDoc doc = new XmlDoc(startXml)
println "data1: ${doc.getText('//data1')}" //returns null
println "data2: ${doc.getText('//data2')}" //returns 'test'
println "data1 with namespace: ${doc.getText('//ns1:data1')}" //Throws XPath expression error

Is there a way to reference elements with a namespace, or is this not supported?

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Hi Chris

       

      Try Path utility (note xmlns for defining namespace):

       

      Cheers
      Rado

        CommentAdd your comment...