Loading ...
Sorry, an error occurred while loading the content.

use XML::Simple;

Expand Messages
  • club_400
    Not sure if anyone on this list uses perl and XML. When I do a loop through the xml document with the perl module I want the data to be shown in id order. ie:
    Message 1 of 2 , Mar 2 8:50 AM
    • 0 Attachment
      Not sure if anyone on this list uses perl and XML.

      When I do a loop through the xml document with the
      perl module I want the data to be shown in id order.
      ie:
      <LINK id=1></LINK>
      <LINK id=2></LINK>
      It seems to display the xml data in order
      for the first 4 records and then it goes completely
      random.

      You can view this project at
      http://64.172.154.146/index_xml.pl?xml_page=index.xml

      Thanks

      Mike Aarset

      here is some code

      #START SAMPLE CODE

      my $xs1 = XML::Simple->new();
      my $doc = $xs1->XMLin("data/sidebar.xml");

      foreach my $key (keys (%{$doc->{LINK}})){
      $page = $doc->{LINK}->{$key}->{'HREF'};
      $name = $doc->{LINK}->{$key}->{'NAME'};
      print "<NOBR><a href=$page>";
      print "$name <img src=images/blue_dot.gif width=5 height=5
      border=0></A>";
      print "</NOBR><BR>";
      }
      #END SAMPLE CODE

      # XML DOCUMENT sidebar.xml
      <?xml version="1.0"?>
      <SIDEBAR>
      <LINK id="1">
      <NAME>Home</NAME>
      <HREF>default.pl</HREF>
      <STATUS></STATUS>
      </LINK>
      <LINK id="2">
      <NAME>Parts</NAME>
      <HREF>vh_search.pl</HREF>
      <STATUS></STATUS>
      </LINK>
      <LINK id="4">
      <NAME>Contact Us</NAME>
      <HREF>mailto:parts@...</HREF>
      <STATUS></STATUS>
      </LINK>
      <LINK id="5">
      <NAME>Vin Search</NAME>
      <HREF>vh_searchvin.pl</HREF>
      <STATUS></STATUS>
      </LINK>
      </SIDEBAR>

      #END OF XML document
    • Jenda Krynicky
      From: club_400 ... I m afraid you ll have to sort the keys. Something like : foreach my $key (sort
      Message 2 of 2 , Mar 4 4:30 AM
      • 0 Attachment
        From: "club_400" <club_400@...>
        > When I do a loop through the xml document with the
        > perl module I want the data to be shown in id order.
        > ie:
        > <LINK id=1></LINK>
        > <LINK id=2></LINK>
        > It seems to display the xml data in order
        > for the first 4 records and then it goes completely
        > random.
        >
        > #START SAMPLE CODE
        >
        > my $xs1 = XML::Simple->new();
        > my $doc = $xs1->XMLin("data/sidebar.xml");
        >
        > foreach my $key (keys (%{$doc->{LINK}})){

        I'm afraid you'll have to sort the keys. Something like :

        foreach my $key
        (sort {$doc->{LINK}->{$a}->{'id'} <=> $doc->{LINK}->{$b}->{'id'}}
        keys (%{$doc->{LINK}})){

        Jenda


        =========== Jenda@... == http://Jenda.Krynicky.cz ==========
        There is a reason for living. There must be. I've seen it somewhere.
        It's just that in the mess on my table ... and in my brain.
        I can't find it.
        --- me
      Your message has been successfully submitted and would be delivered to recipients shortly.