fork(1) download
  1. def string = '''<soapenv:Envelope xmlns:soapenv="http://s...content-available-to-author-only...p.org/soap/envelope/" xmlns:ns="http://w...content-available-to-author-only...l.org/OTA/2003/05">
  2. <soapenv:Header/>
  3. <soapenv:Body>
  4. <OTA_HotelAvailRQ EchoToken="1234" RateRangeOnly="true" Target="Test" TimeStamp="2006-07-04T09:00:27.1343316+02:00" TransactionIdentifier="b123456789" Version="4.000" xsi:schemaLocation="http://w...content-available-to-author-only...l.org/OTA/2003/05 OTA_HotelAvailRQ.xsd" xmlns="http://w...content-available-to-author-only...l.org/OTA/2003/05" xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance">
  5. <AvailRequestSegments>
  6. <AvailRequestSegment>
  7. <HotelSearchCriteria>
  8. <Criterion>
  9. </Criterion>
  10. </HotelSearchCriteria>
  11. </AvailRequestSegment>
  12. </AvailRequestSegments>
  13. </OTA_HotelAvailRQ>
  14. </soapenv:Body>
  15. </soapenv:Envelope>'''
  16.  
  17. def xml = new XmlSlurper(false, false).parseText(string)
  18. def map = ['03062': 'ABC', '03092': 'ABC', '03144': 'ABC']
  19.  
  20. criteria = xml.'**'.find {'Criterion' == it.name()}
  21. criteria.appendNode {
  22. map.each { k, v ->
  23. HotelRef('ChainCode' : v, 'HotelCode': k)
  24. }
  25. }
  26. println groovy.xml.XmlUtil.serialize(xml)
Success #stdin #stdout 1.32s 2254848KB
stdin
Standard input is empty
stdout
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:ns="http://w...content-available-to-author-only...l.org/OTA/2003/05" xmlns:soapenv="http://s...content-available-to-author-only...p.org/soap/envelope/">
  <soapenv:Header/>
  <soapenv:Body>
    <OTA_HotelAvailRQ xmlns="http://w...content-available-to-author-only...l.org/OTA/2003/05" xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance" Target="Test" Version="4.000" TransactionIdentifier="b123456789" xsi:schemaLocation="http://w...content-available-to-author-only...l.org/OTA/2003/05 OTA_HotelAvailRQ.xsd" EchoToken="1234" RateRangeOnly="true" TimeStamp="2006-07-04T09:00:27.1343316+02:00">
      <AvailRequestSegments>
        <AvailRequestSegment>
          <HotelSearchCriteria>
            <Criterion>
              <HotelRef ChainCode="ABC" HotelCode="03062"/>
              <HotelRef ChainCode="ABC" HotelCode="03092"/>
              <HotelRef ChainCode="ABC" HotelCode="03144"/>
            </Criterion>
          </HotelSearchCriteria>
        </AvailRequestSegment>
      </AvailRequestSegments>
    </OTA_HotelAvailRQ>
  </soapenv:Body>
</soapenv:Envelope>