fork(3) download
  1. def xmlString = """<soap:Envelope xmlns:soap="http://s...content-available-to-author-only...p.org/soap/envelope/" xmlns:ns2='test' xmlns:ns9='test2'>
  2. <soap:Body>
  3. <ns2:analyzeEffectOfReplaceOfferResponse>
  4. <ns2:productOfferings>
  5. <ns2:productOffering xsi:type="ns2:ProductOfferingInstanceCore" xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance">
  6. <ns2:opExtn>C_P87531945-0993-46d1-8f23-ed23caa6e0cf</ns2:opExtn>
  7. <ns2:productOffering>
  8. <ns9:id>8447669</ns9:id>
  9. </ns2:productOffering>
  10. <ns2:productOffering>
  11. <ns9:id>8447100</ns9:id>
  12. </ns2:productOffering>
  13. </ns2:productOffering>
  14. </ns2:productOfferings>
  15. </ns2:analyzeEffectOfReplaceOfferResponse>
  16. </soap:Body>
  17. </soap:Envelope>"""
  18.  
  19. def newOfferings = [8447101, 8447102]
  20.  
  21. def xml = new XmlSlurper().parseText(xmlString)
  22.  
  23. def offerings = xml.'**'.find{it.name() == 'productOfferings'}
  24.  
  25. newOfferings.each { val ->
  26. offerings.appendNode {
  27. 'ns2.productOffering' {
  28. 'ns9.id'(val)
  29. }
  30. }
  31. }
  32.  
  33. println groovy.xml.XmlUtil.serialize(xml)
Success #stdin #stdout 1.65s 133116KB
stdin
Standard input is empty
stdout
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://s...content-available-to-author-only...p.org/soap/envelope/">
  <soap:Body>
    <ns2:analyzeEffectOfReplaceOfferResponse xmlns:ns2="test">
      <ns2:productOfferings>
        <ns2:productOffering xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance" xsi:type="ns2:ProductOfferingInstanceCore">
          <ns2:opExtn>C_P87531945-0993-46d1-8f23-ed23caa6e0cf</ns2:opExtn>
          <ns2:productOffering>
            <ns9:id xmlns:ns9="test2">8447669</ns9:id>
          </ns2:productOffering>
          <ns2:productOffering>
            <ns9:id xmlns:ns9="test2">8447100</ns9:id>
          </ns2:productOffering>
        </ns2:productOffering>
        <ns2.productOffering>
          <ns9.id>8447101</ns9.id>
        </ns2.productOffering>
        <ns2.productOffering>
          <ns9.id>8447102</ns9.id>
        </ns2.productOffering>
      </ns2:productOfferings>
    </ns2:analyzeEffectOfReplaceOfferResponse>
  </soap:Body>
</soap:Envelope>