in reply to Re: perl parsing xml
in thread perl parsing xml

I was actually using XML::Simple which was printing something like above. But the problem I want something like this
semt.002.001.01.PrvsRef semt.002.001.01.RltdRef
The output is to related to semt.002.001.01 which is the root level. It just an example output file .It has various types with associated names. Like name = PrvsRef type = AdditionalReference2, name = RltdRef, type = AdditionalReference2. Therefore semt.002.001.01.PrvsRef;semt.002.001.01.RltdRef . Now I need to parse the xml file for the type "AdditionalReference2" it again has three different names with associated types. There fore semt.002.001.01.PrvsRef.RefIssr;semt.002.001.01.Ref so on . Therefore I need to look for the types Ref, RefIssr,MsgNm in the xs:complex type and append the names to the rootlevel. It has to find the root level and then append the intermediate nodes available in the xml file.

Replies are listed 'Best First'.
Re^3: perl parsing xml
by GrandFather (Saint) on Jan 23, 2008 at 03:26 UTC

    If I understand what you want then adding:

    my $type = $_->att ('type'); return unless defined $type && $type eq 'AdditionalReference2';

    following the my @path; line in showNesting does the trick and (for the sample data I used above) prints:

    semt.002.001.01.PrvsRef semt.002.001.01.RltdRef

    Perl is environmentally friendly - it saves trees
      but i can;t hard code additionalreference2 as it could be varying. and when finally i want the output to be
      semt.002.001.01 semt.002.001.01.PrvsRef semt.002.001.01.PrvsRef.Ref semt.002.001.01 semt.002.001.01.PrvsRef semt.002.001.01.PrvsRef.RefIssr semt.002.001.01.PrvsRef.RefIssr.BICOrBEI
      as i explained above. first just the root , root +intermediate node, root+intermediate node+leaf

        If you want people to provide an answer to help solve your problem, you have to present the problem in a lucid fashion. I have re-read all the material you have posted in this thread and still have very little idea what it is that you are trying to achieve. However if you examine the code samples I have provided above I am sure the key components of your solution are there.

        You need to have a clear idea of what the selection criteria are for the data you wish to extract before you can write the code to do that. So far, even if you know what the criteria are, you've not been able to express them clearly.


        Perl is environmentally friendly - it saves trees