Groovy web console

subscribe to the feed Subscribe
to this
site
parse xml find element value by its sibling (via #groovywebconsole)
tweet this snippet Tweet
this
script

parse xml find element value by its sibling

Published 6 months ago by nmrao with tags parse xml
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = """<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <soap:Body>   <DataResponse xmlns="http://eh.dummy.com">       <onlinePartyData xmlns="">         <tabs  xmlns="http://eh.dummy.com">            <tabs_InnerSet>                <Tabs_InnerSet_TupleType>                  <tab>                      <DISPLAY_TEXT>DESCRIPTION 1</DISPLAY_TEXT>                      <qsets>                         <qsets_InnerSet>                            <Qsets_InnerSet_TupleType>                               <qset>                                  <SET_CD>QS1</SET_CD>                                  <VISIBLE>true</VISIBLE>                               </qset>                            </Qsets_InnerSet_TupleType>                            <Qsets_InnerSet_TupleType>                               <qset>                                  <SET_CD>QS2</SET_CD>                                  <VISIBLE>true</VISIBLE>                               </qset>                              <qset>                                  <SET_CD>QS3</SET_CD>                                  <VISIBLE>false</VISIBLE>                               </qset>                            </Qsets_InnerSet_TupleType>                          </qsets_InnerSet>                     </qsets>                   </tab>               </Tabs_InnerSet_TupleType>             </tabs_InnerSet>         </tabs>       </onlinePartyData>   </DataResponse> </soap:Body>  </soap:Envelope> """ 
def parsedXml = new XmlSlurper().parseText(xml) 
def result = parsedXml.'**'.findAll {it.VISIBLE == true}.SET_CD.join(',') 
println result 
assert result instanceof String