Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Groovy: How to check multiple tag value in xml?

Highlighted

Groovy: How to check multiple tag value in xml?

New Contributor

and i want to check each start tag value and then update value of runAs i have tried this :

<?xml version="1.0" encoding="UTF-8"?><service>
  <rs>
    <Id>
      <details>
        <start>2017-10-07</start>
        <startDate>2017-02-02</startDate>
        <endDate>2017-03-02</endDate>
        <runAs>false</runAs>
        <makeVersion>1</makeVersion>
        <patch>this is  patch</patch>
        <parameter>1</parameter>
      </details>
    </Id>
    <person>
      <details>
        <start>2017-09-07</start>
        <startDate>2017-02-02</startDate>
        <endDate>2017-03-02</endDate>
        <runAs>true</runAs>
        <makeVersion>1</makeVersion>
        <patch>this is  patch</patch>
        <parameter>1</parameter>
      </details>
    </person>
  </rs>
  <country>
  <details>
        <start>2017-09-07</start>
        <startDate>2017-02-02</startDate>
        <endDate>2017-03-02</endDate>
        <runAs>true</runAs>
        <makeVersion>1</makeVersion>
        <patch>this is  patch</patch>
        <parameter>1</parameter>
      </details>
  </country>
</service>
  def xml = new XmlParser().parseText(content)
            def start=xml.'**'.details.start[0].text();
            def  run=xml.'**'.details.start[0].text();
            if(start!=currentDate &&  run!='false'){

                xml.'**'.details.runAs[0].value="false";
            }
           else {
                xml.'**'.details.find({p->

                    p.start[0].value= subtractDays(p.start[0].text(),p.parameter[0].text()).toString()
                    p.runAs[0].value='false';
                })
            }
            def newxml=XmlUtil.serialize(xml)

but it have updated only rs->Id->details->runAs value, what should i change to update evry runAs tag value and in certain case update every start tag values too?

Don't have an account?
Coming from Hortonworks? Activate your account here