i found this supergroovy function of XmlParser().parseText(…).
It works fine for me without namespaces… now i have the following XML (SoapRequest):
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://xxx" xmlns:xsd="http://xxy"
xmlns:xsi="http://xxz">
<soap:Body>
<MG_Input xmlns="http://yxx">
<Accnr>001</Accnr>
[...]
My target is to acquire the Accnr over the XmlParser.
I assumed that it could work this way:
input = new File('c:/temp/03102890.xml-out')
def soapns = new groovy.xml.Namespace("http://xxx",'soap')
def xsdns = new groovy.xml.Namespace("http://xxy")
def xsins = new groovy.xml.Namespace("http://xxz")
def ordns = new groovy.xml.Namespace("http://yxx")
xml = new XmlParser().parseText(input.getText())
println xml[soapns.Envelope][soapns.Body][ordns.MG_Input][Accnr][0].text()
But this doesnt really work…
Has anybody an idea of how to handle this ‘easy’? I just cant get it to work with examples from google…
Your expression was incorrect – the
xmlvar is already the root element of the xml document (in this casesoap:Envelope) – so you just need to traverse from there. So, the expression you’re looking for is: