Re: Help with accessing an unknown set of data generated by XML::Simple

Paulo SantAnna <[email protected]> Fri, 17 Feb 2012 16:51:40 -0800
Newsgroups gmane.comp.lang.perl.xml
Message-ID <CAK0DBtZ7GSknLbCcQzahjbe5KHeuhD=+pZFvxK-bza6+XwY9Yg@mail.gmail.com>
> But now, I would like to move the quality of my Perl programs up a notch and use some of the standard modules to guarantee good XML output.

Take a look at the Perl & XML book from O'Reilly, also I think the
XML::Smart module has more resources than XML::Simple and handle
better more
complex docs. Other good candidates depending on your task are
XML::XPath and XML:Twig (for large docs and using callbacks)

Thanks,

Paulo

On Fri, Feb 17, 2012 at 2:33 PM, Stephen Wilcoxon <[email protected]> wrote:
> I think what you want to do should be doable.  However, I'm not quite
> following your descriptions.  Could you provide a sample $xmldata,
> what the placeholders are you're looking for in it, and what you want
> the output XML to be (or what you want the $xmldata to be prior to
> output)?
>
> On Fri, Feb 17, 2012 at 16:26, Dale Puckett <[email protected]> wrote:
>> I have been working with XML for several years now and have always been able to get the job done. But now, I would like to move the quality of my Perl programs up a notch and use some of the standard modules to guarantee good XML output.
>>
>> Unfortunately, I've hit a stumbling block and can't seem to get my head around the solution.
>>
>> I want to read the data from an XML Sample file with XMLin and then be able to access it and manipulate it by retrieving values from our database, asset files and other sources and putting the retuned values back in the XML in place of the placeholders I use in the XML Sample file. Thee placeholders actually tell me where to go to get the data that I am going to return for each ad scheduled for a particular day.
>>
>> Here's what I have tried so far.
>>
>> -----
>> use strict;
>> use feature 'say';
>> use XML::Simple;
>> use Data::Dumper;
>>
>> my $xmldata = XMLin('files/test.xml', ForceArray => 1, KeepRoot => 1);
>> my %data = Dumper ($xmldata);
>>
>> my $href = \%data;
>>
>> for my $key (keys %{$href}){
>>  say $key => ${$href}{$key};
>>  say $key => ${$href}{value}
>> }
>> -----
>>
>> What I want to do is get a list of keys with the values in the XML Sample file into memory so I can access them individual, get the data required for any particular node and eventually write out a complete file with all of the information returned for each ad scheduled that day.
>>
>> The code above returns the same answer as:
>>
>> print Dumper ($xmldata);
>>
>> I've read several tutorials regarding references but I cannot seem to get my head wrapped around it. Does anyone know of a site where I can find example code used by someone trying to accomplish the same task?
>>
>> I already have the code to get the data and write it out. I just need to be able to analyze the XML Sample and write a program to output it for each ad running on a given day.
>>
>> All the tutorials and sample code I have found so far all assumes you know the names of the XML elements. In this case, I don't, and in fact they are different for every project I do so It would be a very long and tedious process to hand code a program to access the keys by hand.
>>
>> All help will really be appreciated.
>>
>> Thanks,
>>
>> Dale
>> -----
>> Dale L. Puckett, Director of Operations
>> Midwest Division, Brainworks Software Development Corporation
>> 7570 West 21st Street North, Building 1010C, Wichita, KS 67205
>> [email protected], 631-963-5555
>>
>> _______________________________________________
>> Perl-XML mailing list
>> [email protected]
>> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> _______________________________________________
> Perl-XML mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs