Parser Groovy XML Tutorial Namespace Handling

I found this supertomb 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 goal is to acquire Accnr over XmlParser. I suggested that it might work as follows:

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 it really doesn't work ...

Does anyone have an idea on how to handle this “easy”? I just can't get it to work with google examples ...

+5
source share
2 answers

- xml var XML- ( soap:Envelope) - . , , , :

println xml[soapns.Body][ordns.MG_Input].Accnr[0].text()
+8

:

, . , print xml xml = new XmlParser().parseText(input.getText()), , JSON, . , .

+1

All Articles