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

Dale Puckett <[email protected]> Sat, 18 Feb 2012 02:35:34 +0000
Newsgroups gmane.comp.lang.perl.xml
Message-ID <CB646985.1B1AC%[email protected]>
Additional Clarification:

>From the section of the XML Sample attached earlier that reads:

<TEMPWEBFORMTEXT><![CDATA[webtag:ALL_AD_TEXT]]></TEMPWEBFORMTEXT>
		<TEMPRAWTEXT><![CDATA[addquery:rawText]]></TEMPRAWTEXT>
		<PUBID>db:pubID</PUBID>
		<ACCTID>db:accountID</ACCTID>
		


I would like to see an array or hash that contains:

"TEMPWEBFORMTEXT", "webtag:ALL_AD_TEXT"
"TEMPRAWTEXT", "addquery:rawText"
"PUBID", "db:pubID"
"ACCTID", "db:accountID"
And, maybe:

"Jobs:, ""

If I could get these data pairs I have the support code to finish the rest
of he project.

Thanks,

Dale




On 2/17/12 7:02 PM, "Francisco Obispo" <[email protected]> wrote:

>What I'm usually doing is sticking to XML::LibXML and all of its bundled
>libraries, so I keep less external dependencies.
>
>This is unless the document is so large, that I need a SAX parser, in
>which case I use XML::SAX (using XS), which has proven to be very fast.
>
>One of the techniques I ended up using for my internal projects, was
>modeling an XPath-based Parser, that allowed me to take advantage of
>XML::LibXML::XPathContext to set up a base hash that could be populated
>with XPath expressions.
>
>The XPath expressions would then be evaluated with the xml document, and
>their values returned in a hash with its values.
>
>The advantage of this mode, is that you can keep all of your parsing in
>one place, and also, limit the parser to return just what you need,
>instead of the whole document.
>
>In addition, the XPath expressions can be pre-compiled, so that if you
>need to process several documents, you would gain some speed.
>
>
>Francisco
>
>
>On Feb 17, 2012, at 4:51 PM, Paulo SantAnna wrote:
>
>>>  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
>
>Francisco Obispo 
>email: [email protected]
>Phone: +1 650 423 1374 || INOC-DBA *3557* NOC
>PGP KeyID = B38DB1BE
>

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs