Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Dear Monks, I am working on a old code which uses XMLSimple to parse XML data.
I have a data set in which i need to relate the tags by occurance like Phone tag if followed by preceding Name tag then it is related to it.
I can't do this with XMLSimple as the data structure it returns creates the keys of Name tag and Phone tag thereby grouping the data related to them.
Please see this example
use XML::Simple; use Data::Dumper; my $data=qq(<Data><Name><Lname>xyz</Lname><Fname>abcd</Fname></Name><P +hone><Mobile>123456789</Mobile><Home>55656556</Home></Phone><Phone><M +obile>123456789</Mobile><Home>55656556</Home></Phone><Name><Lname>UTV +</Lname><Fname>EFGH</Fname></Name><Phone><Mobile>123456789</Mobile><H +ome>55656556</Home></Phone></Data>); my $ref=XMLin($data); print Dumper($ref); which shows output $VAR1 = { 'Phone' => [ { 'Home' => '55656556', 'Mobile' => '123456789' }, { 'Home' => '55656556', 'Mobile' => '123456789' }, { 'Home' => '55656556', 'Mobile' => '123456789' } ], 'Name' => [ { 'Lname' => 'xyz', 'Fname' => 'abcd' }, { 'Lname' => 'UTV', 'Fname' => 'EFGH' } ] };
From this i can't make out which phone number is associated with which name, Please help.

Out of sheer desperation may be i can use this

#on above $data i can split up the above string with each #Name tag followed by Phone tags associated with this my @namephn=map{m/<Name>.*?<\/Phone>/g } $data; print join "\n",@namephn; #---------- Output ------------- <Name><Lname>xyz</Lname><Fname>abcd</Fname></Name><Phone><Mobile>12345 +6789</Mobile><Home>55656556</Home></Phone> <Name><Lname>UTV</Lname><Fname>EFGH</Fname></Name><Phone><Mobile>12345 +6789</Mobile><Home>55656556</Home></Phone>

But how do i make that lazy ? operator match more than one phone tag till the next Name tag :-(

In reply to Relating data parsed with XMLSimple by mohan2monks

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [erix]: yes. Deplorable marto, deplorable.
    [marto]: the situation seemed similar to this one, majority of the contributrions are nonsense, doesn't address any questions ...
    [marto]: meh, I've been called worse :P
    [marto]: deplorable is actually not bad for this point in the day :P
    [erix]: we aim to satisfy
    [erix]: churches are good excuses for large-scale architecture -- which is nice
    [marto]: not to be confused with Chvrches

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (9)
    As of 2017-07-28 15:50 GMT
    Find Nodes?
      Voting Booth?
      I came, I saw, I ...

      Results (431 votes). Check out past polls.