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

Extracing XML data to perl variables?

Expand Messages
  • chipwillis2003
    Hi, I am trying to extract the 641 and 0 from a web page that returns the values in XML. How can I go about
    Message 1 of 2 , Nov 6, 2006
    • 0 Attachment
      Hi,
      I am trying to extract the "<ActivityID>641</ActivityID>"
      and "<ErrorID>0</ErrorID>" from a web page that returns the values
      in XML. How can I go about putting these values into a Perl variable
      so I can use them for further processing?

      Here is the XML

      <?xml version="1.0" ?>
      - <iLinc:Response version="8.0.1" xmlns:iLinc="http://www.ilinc.com">
      - <iLinc:AddActivityBasicResponse Reference="101">
      <ActivityID>641</ActivityID>
      <ErrorID>0</ErrorID>
      <ErrorStr />
      </iLinc:AddActivityBasicResponse>
      </iLinc:Response>

      Thank you,
      Chip
    • Jenda Krynicky
      From: chipwillis2003 ... There are quite a few XML modules on CPAN (http://search.cpan.org) in this case it would probably be
      Message 2 of 2 , Nov 14, 2006
      • 0 Attachment
        From: "chipwillis2003" <chipwillis2003@...>
        > Hi,
        > I am trying to extract the "<ActivityID>641</ActivityID>"
        > and "<ErrorID>0</ErrorID>" from a web page that returns the values in
        > XML. How can I go about putting these values into a Perl variable so I
        > can use them for further processing?
        >
        > Here is the XML
        >
        > <?xml version="1.0" ?>
        > <iLinc:Response version="8.0.1" xmlns:iLinc="http://www.ilinc.com">
        > <iLinc:AddActivityBasicResponse Reference="101">
        > <ActivityID>641</ActivityID>
        > <ErrorID>0</ErrorID>
        > <ErrorStr />
        > </iLinc:AddActivityBasicResponse>
        > </iLinc:Response>
        >
        > Thank you,
        > Chip

        There are quite a few XML modules on CPAN (http://search.cpan.org) in
        this case it would probably be easiest to just use XML::Simple:

        use XML::Simple qw(XMLin);

        $data = XMLin($xml);

        my $activity = $data->{'iLinc:AddActivityBasicResponse'}{ActivityID};
        my $error = $data->{'iLinc:AddActivityBasicResponse'}{ErrorID};

        HTH, Jenda
        ===== Jenda@... === http://Jenda.Krynicky.cz =====
        When it comes to wine, women and song, wizards are allowed
        to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery
      Your message has been successfully submitted and would be delivered to recipients shortly.