0

I have the below xml, Updated added "symptoms"

<EBF>
<EBFINFO>
    <EBFNUM>EBF262323</EBFNUM>  
    <RELEASEDATETIME>May 06, 2011</RELEASEDATETIME>
    <SYMPTOMS>
    <br> INFA252994 - 910 : While running concurrent session Workflow manager hangs and workflow monitor does not respond</br>
    <br> INFA262323 - 910 : pmcmd, pmdtm and all LM clients on Windows fail to connect to IS when IPv6 is installed but all IPv6 interfaces are disabled</br>
    </SYMPTOMS>
    <FILES>
       <FILE>
        <PATH>H:\EBF262323\EBF262323_Client_Installer_win32_x86\EBFs\clients\PmClient\client\bin\ACE.dll_bak</PATH>
        <CHECKSUM>303966974</CHECKSUM>
        <AFFECTEDFILES>
            <CHECKSUM>3461283269</CHECKSUM>
            <PATH>C:\clients\PmClient\CommandLineUtilities\PC\server\bin\ACE.dll</PATH>
            <PATH>C:\clients\PmClient\client\bin\ACE.dll</PATH>
        </AFFECTEDFILES>
       </FILE>
    </FILES>
    <NOTES>
    </NOTES>
</EBFINFO>
</EBF>

Note: In the above xml ebf\enfinfo\files\file\affectedfiles\path and ebf\enfinfo\files\file can be one or more

which I am parsing and generating another xml out of it

    def records = new XmlParser().parseText(rs)
    csm.ebfHistory(){
    records.EBFINFO.each{
    ebfHistory_info(num:it.EBFNUM.text(),
        release_date_time:it.RELEASEDATETIME.text()
        ){

            it.FILES.FILE.each{ //says Exception in thread "main" java.lang.NullPointerException: Cannot get property 'FILES' on null object
                ebfHistory_fileinfo(file_path:it.PATH.text(),
                    file_checksum:it.CHECKSUM.text()
                ){
                    ebfHistory_fileinfo_affectedfiles(
                        afile_checksum:it.CHECKSUM.text(),
                        afile_path:it.PATH.text()
                        )
                }
            }
        }
  }             
}

something like below

<ebfHistory>
    <ebfHistory_info num="EBF262323",release_date_time="May 06, 2011">
        <ebfHistory_fileinfo file_checksum="303966974">
            <ebfHistory_fileinfo_affectedfiles afile_checksum="3461283269">
                <path>C:\clients\PmClient\CommandLineUtilities\PC\server\bin\ACE.dll</path>
                <path>C:\clients\PmClient\client\bin\ACE.dll</path>
            </ebfHistory_fileinfo_affectedfiles>
        </ebfHistory_fileinfo>
    </ebfHistory_info>
</ebfHistory>

but instead I get Exception in thread "main" java.lang.NullPointerException: Cannot get property 'FILES' on null object where am i going wrong? Please help somebody. Thanks

Updated code (working)

def records = new XmlParser().parseText(rs)
        csm.ebfHistory(){   
            records.EBFINFO.each{   ebfinfo ->
                ebfHistory_info(num:ebfinfo.EBFNUM.text(),
                    release_date_time:ebfinfo.RELEASEDATETIME.text())
                    {
                        ebfinfo.SYMPTOMS.br.each{
                            ebfHistory_symptom(name:it.text())
                        }
                    }
            }   
            ebfHistory_dump(rs){
                "${rs}"
            }
        }

1 Answer 1

2

The it no longer refers to each EBFINFO, because you are in another closure--the ebfHistory_info closure.

Instead, explicitly name the EBFINFO object:

records.EBFINFO.each { ebfinfo -> // <-- Give it a name
    ebfHistory_info(num:it.EBFNUM.text(),
                    release_date_time:it.RELEASEDATETIME.text()) {
        ebfinfo.FILES.FILE.each { // <-- Use the name here

Same thing in the ebfHistory_fileinfo_affectedfiles parameters.

Sign up to request clarification or add additional context in comments.

6 Comments

EBFINFO can be one or more so still can it be uniquely identified?
The it variable is an implicit variable that is the parameter of a single-argument closure. As I said, you're creating another closure when you call ebfHistory_info, thus it is re-bound in the new closure's scope. You must explicitly name the EBFINFO instance instead of using the implicit it, because it is no longer the EBFINFO once you're in the new closure.
Please look at my updated question, i tried you way but getting some error
@AbhishekSimon Oh, I'm stuck in Ruby mode today--the Groovy syntax is different; updated answer.
one small correction, it has to be replaced by ebfinfo in its closure. I updated my question with working code. Thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.