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

Dale Puckett <[email protected]> Sat, 18 Feb 2012 02:24:25 +0000
Newsgroups gmane.comp.lang.perl.xml
Message-ID <CB64654D.1B194%[email protected]>
Thanks for the tips Francisco!

Earlier, Stephen asked me to send an example of one of the XML Sample
files and an output file. I accidentally hit reply when I sent him a
sample file and an output file from an extractor generated from it. I
don't have an output file here at home but I wanted to attach another XML
Sample file. Some of the Sample files we get from vendors are simple like
this one. Others are more complex.

Essentially what I need to be able to do is pull each key and value out of
the output of XMLin or one of the other many parsers available now. Once I
get the data where I can access it, I have the rest of support code needed
to build the extractor. The content node of the XML in the sample file
contains a sudo language placeholder that my program uses to know where to
access the data either from our database or from any number different
asset files on the file system.

Any thoughts along this line will be appreciated.

Thanks Again,

Dale



I'm going to 

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
Westward_LNG-JobNetworkFinal.xml (application/xml, 1.2 KB)
<?xml version="1.0" encoding="Windows-1252" standalone="no"?>
<JOBS>
	<JOB>
		<TEMPWEBFORMTEXT><![CDATA[webtag:ALL_AD_TEXT]]></TEMPWEBFORMTEXT>
		<TEMPRAWTEXT><![CDATA[addquery:rawText]]></TEMPRAWTEXT>
		<PUBID>db:pubID</PUBID>
		<ACCTID>db:accountID</ACCTID>
		<JOB_ID>db:adID</JOB_ID>
		<AD_TYPE>db:adCode</AD_TYPE>
		<COMPANY_NAME>webtag:COMPANY_NAME</COMPANY_NAME>
		<CONFIDENTIAL_COMPANY>webtag:CONFIDENTIAL</CONFIDENTIAL_COMPANY>
		<TITLE>webtag:JOB_TITLE</TITLE>
		<CATEGORY>db:classID</CATEGORY>
		<CITY>webtag:ALL_CITY</CITY>
		<STATE>webtag:ALL_STATE</STATE>
		<ZIP>webtag:ALL_ZIP</ZIP>
		<DESCRIPTION><![CDATA[addquery:whichText]]></DESCRIPTION>
		<APPLY_DATA>
			<FIRST_NAME>webtag:APPLY_FIRST</FIRST_NAME>
			<LAST_NAME>webtag:APPLY_LAST</LAST_NAME>
			<PHONE>webtag:CONTACT</PHONE>
			<APPLY_URL>webtag:COMPANY_WEB</APPLY_URL>
			<APPLY_EMAIL>webtag:JOB_EMAIL</APPLY_EMAIL>
		</APPLY_DATA>
		<WEB_ACCOUNT>
		<EMAIL>db:email</EMAIL>
		<COMPANY>db:company</COMPANY>
		</WEB_ACCOUNT>
		<UPSELL>
		<TOTAL_TALENT_REACH>db:adOCFlag40</TOTAL_TALENT_REACH>
		<FEATURED>db:adOCFlag39</FEATURED>
		<PRIORITY>db:adOCFlag41</PRIORITY>
		</UPSELL>
		<PDF>addquery:displayFilelink</PDF>
	</JOB>
</JOBS>