2010-02-16 4 views
0

XmlSlurper를 성공적으로 사용했지만 다음 XML 구문 분석에 어려움을 겪고 있습니다. Pingdom API 호출로 응답합니다. 네임 스페이스 선언 예제를 따르려고했지만 ns1 및 ns2 값에 대한 오류 메시지가 표시됩니다. 아무도 올바른 방향으로 나를 가리킬 수 있습니까? XML은 다음과 같다 : -Groovy/Grails에서 XmlSlurper를 사용하여 Pingdom XML 응답 구문 분석

<?xml version="1.0" encoding="UTF-8"?> 
    <SOAP-ENV:Envelope 
     xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:ns1="urn:methods" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:ns2="urn:PingdomAPI" 
     xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
     SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <SOAP-ENV:Body> 
      <ns1:Auth_loginResponse> 
       <return xsi:type="ns2:Auth_LoginResponse"> 
        <status xsi:type="xsd:int">0</status> 
        <sessionId xsi:type="xsd:string">mysessionId</sessionId> 
       </return> 
      </ns1:Auth_loginResponse> 
     </SOAP-ENV:Body> 
    </SOAP-ENV:Envelope> 

를 XML 변수에 저장되는 XML을주고,이 시도 하나의 문자열

0mysessionId 
+1

정말 완벽한 XML입니까? – Mikezx6r

+0

전혀 보이지 않는 XML –

+0

죄송합니다. 코드 태그에 넣지 않았습니다! – peaky

답변

4

에 그냥 0 mysessionId 합쳐 XmlSlurper 사용 후 :

def records = new XmlSlurper().parseText(xml).declareNamespace(
    'SOAP-ENV':'http://schemas.xmlsoap.org/soap/envelope/', 
    ns1:'urn:methods', 
    xsd:'http://www.w3.org/2001/XMLSchema', 
    xsi:'http://www.w3.org/2001/XMLSchema-instance', 
    ns2:'urn:PingdomAPI' 
) 

println records.'SOAP-ENV:Body'.'ns1:Auth_loginResponse'.return.status 
println records.'SOAP-ENV:Body'.'ns1:Auth_loginResponse'.return.sessionId