sandip has asked for the wisdom of the Perl Monks concerning the following question:

In xml file i have following data where some tags like<ChrgBr> may not be present in every next file. So i want these values to be stored in some variable like var1="405360,00" , var2="DEBT" and so on ,but if <ChrgBr> tag has no value or is absent var2 should have space like var2=" " so that i can put the if condition to print only present varable values in the flat file

SAMPLE DATA XML FILE:1

<IntrBkSttlmAmt Ccy="USD">405360,00</IntrBkSttlmAmt> <ChrgBr>DEBT</ChrgBr> <ChrgsInf> <Amt Ccy=>00.00</Amt> <Agt> <FinInstnId> <ClrSysMmbId> <MmbId>BRANCHNO1</MmbId> </ClrSysMmbId> </FinInstnId> </Agt> </ChrgsInf> <c> <p> SAMPLE DATA XML FILE :2 </p> <c> <IntrBkSttlmAmt Ccy="USD">405360,00</IntrBkSttlmAmt> <ChrgsInf> <Amt Ccy=>00.00</Amt> <Agt> <FinInstnId> <ClrSysMmbId> <MmbId>BRANCHNO1</MmbId> </ClrSysMmbId> </FinInstnId> </Agt> </ChrgsInf>

OUTPUT SAMPLE DATA FLAT FILE :1

var1="405360,00" var2="DEBT" var3="00.00" var4="BRANCHNO1"

OUTPUT SAMPLE DATA FLAT FILE :2

var1="405360,00" var2=" " var3="00.00" var4="BRANCHNO1"

Replies are listed 'Best First'.
Re: XML PARSING of dynamic xml file to flat file
by McA (Priest) on Aug 08, 2013 at 12:38 UTC

    Hi,

    I'm not pretty sure what you want to ask us?

    Do you have some code, that doesn't work as you thought it should? Or do you want us to present a parsing solution for your problem?

    My solution in pseudocode:

    - initialize variable to '' - Look at xml whether corresponding xml tag is present - if yes, than take the value into your variable

    Please be more specific.

    Best regards
    McA

      am new to perl so if i get parsing solution it will be great help. what you said in pseudocode solution is my exact requirement.

        Look at the Super Search facility of perlmonks. You will find so much stuff about XML parsing.

        Have a look at XML::Twig as one of the top rated modules.

        Best regards
        McA