fork 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. <RoomStayCandidates>
  10. <RoomStayCandidate Quantity="1">
  11. <GuestCounts>
  12. <GuestCount AgeQualifyingCode="1" Count="1"/>
  13. </GuestCounts>
  14. </RoomStayCandidate>
  15. </RoomStayCandidates>
  16. </Criterion>
  17. </HotelSearchCriteria>
  18. </AvailRequestSegment>
  19. </AvailRequestSegments>
  20. </OTA_HotelAvailRQ>
  21. </soapenv:Body>
  22. </soapenv:Envelope>'''
  23.  
  24. def xml = new XmlParser(false, false).parseText(string)
  25. def map = ['03062': 'ABC', '03092': 'ABC', '03144': 'ABC']
  26.  
  27. criteria = xml.'**'.find {'Criterion' == it.name()}
  28. def criteriaChilds = criteria.children()
  29. map.each { k, v ->
  30. def nNode = new Node(null, 'HotelRef', [ChainCode:v, HotelCode:k])
  31. criteriaChilds.add(0, nNode)
  32. }
  33. println groovy.xml.XmlUtil.serialize(xml)
Success #stdin #stdout 1.14s 2254848KB
stdin
Standard input is empty
stdout
<?xml version="1.0" encoding="UTF-8"?><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">
  <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" 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">
      <AvailRequestSegments>
        <AvailRequestSegment>
          <HotelSearchCriteria>
            <Criterion>
              <HotelRef ChainCode="ABC" HotelCode="03144"/>
              <HotelRef ChainCode="ABC" HotelCode="03092"/>
              <HotelRef ChainCode="ABC" HotelCode="03062"/>
              <RoomStayCandidates>
                <RoomStayCandidate Quantity="1">
                  <GuestCounts>
                    <GuestCount AgeQualifyingCode="1" Count="1"/>
                  </GuestCounts>
                </RoomStayCandidate>
              </RoomStayCandidates>
            </Criterion>
          </HotelSearchCriteria>
        </AvailRequestSegment>
      </AvailRequestSegments>
    </OTA_HotelAvailRQ>
  </soapenv:Body>
</soapenv:Envelope>