Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (10)
    As of 2014-07-28 06:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (191 votes), past polls