#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    16
    Rep Power
    0

    XML::Simple Data::Dumper w Perl


    Here is the code that reads in the XML file, parses it using XML::Simple and dumps the contents to screen:

    use XML::Simple;
    use Data:umper;

    my $xml = "";

    open(FILE, "sampleOrder.xml") || die "Cannot open data file";
    while (<FILE>) {
    $xml .= $_;
    }
    close FILE;

    my $hashref = XMLin($xml);

    print Dumper($hashref);

    What I see is a bunch of embedded hashes similar to this:

    $VAR1 = {
    'Message' => [
    {
    'TestOrderRequest' => {
    'FulfillmentData' => {
    'FulfillmentServiceLevel' => 'Standard',
    'PostalCode' => '98004',
    'FulfillmentMethod' => 'Ship',
    'FulfillmentCenterID' => '0'
    },
    'Item' => {
    'SKU' => '1234',
    'Quantity' => '2'
    },
    'BillingData' => {
    'CreditCard' => {
    'Issuer' => 'Visa'
    },
    'BuyerEmailAddress' => 'joesmith@hotmail.com'
    }
    },
    'MessageID' => '1'
    },

    What I would like is a simple way to extract into variables that contain values, eg. $firstName = $myValues{'firstName'} Does anyone know how this can be done without having to know the tree structure of the hashes? Please forgive the newbieness...
    Last edited by bwebb@SCGI; July 26th, 2002 at 01:08 PM.

IMN logo majestic logo threadwatch logo seochat tools logo