Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

XML Parser clobbering Multiple occurances of element

by Random_Walk (Parson)
on Aug 12, 2005 at 12:08 UTC ( #483255=perlquestion: print w/ replies, xml ) Need Help??
Random_Walk has asked for the wisdom of the Perl Monks concerning the following question:

My dear brothers and sisters in Perl I beg your assistance,

I am lost in a twisty maze of TFM's and my little brain is overflowing. The answer must be there somewhere but I am going snowblind from staring at reams of virgin white manpages.

I am using SOAP to get some lists of events back from Tivoli Enterprise Portal (Formaly CandleNet Portal). If I dump the raw XML from SOAP::Lite with the option $soap -> outputxml(1) I get several rows of data, here is a reduced example ...
<?xml version="1.0" encoding="ISO-8859-1"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env +elope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/enco +ding/"> <SOAP-ENV:Body><SOAP-CHK:Success xmlns:SOAP-CHK = "http://soa +ptest1/soaptest/" xmlns="urn:candle-soap:attributes"><TABLE name="KMQ +.QMEVENTC"> <OBJECT>Current_Events</OBJECT> <DATA> <ROW> <Origin_Node>TQTHSL1:HSL:MQ</Origin_Node> <Reporting_MQ_Manager_Name>TQTHSL1</Reporting_MQ_Manager_Name> <Reporting_Host_Name>hsl</Reporting_Host_Name> <Event_ID>C0000000</Event_ID> <Event dt="number">Channel_Stopped</Event> <Event_Date_and_Time>1050810083840000</Event_Date_and_Time> </ROW> <ROW> <Origin_Node>TQTHSL1:HSL:MQ</Origin_Node> <Reporting_MQ_Manager_Name>TQTHSL1</Reporting_MQ_Manager_Name> <Reporting_Host_Name>hsl</Reporting_Host_Name> <Event_ID>C0000001</Event_ID> <Event dt="number">Channel_Stopped</Event> <Event_Date_and_Time>1050810083842000</Event_Date_and_Time> </ROW> <ROW> <Origin_Node>TQTHSL1:HSL:MQ</Origin_Node> <Reporting_MQ_Manager_Name>TQTHSL1</Reporting_MQ_Manager_Name> <Reporting_Host_Name>hsl</Reporting_Host_Name> <Event_ID>C0000002</Event_ID> <Event dt="number">Channel_Stopped</Event> <Event_Date_and_Time>1050810083843000</Event_Date_and_Time> </ROW> </DATA> </TABLE> </SOAP-CHK:Success></SOAP-ENV:Body></SOAP-ENV:Envelope>

However when I remove the $soap -> outputxml(1) directive and let SOAP::Lite pass it off to the parser I only get the last row of data in the result (I am checking paramsout() as well, here is what I get back.

Got result: HASH(0x207f2ed8) $VAR1 = { 'OBJECT' => 'Current_Events', 'DATA' => { 'ROW' => { 'Event' => 'Channel_Stopped', 'Event_ID' => 'C0000002', 'MQ_Manager_Subsystem' => '', 'Event_Date_and_Time' => '1050810083843000', 'Reporting_Host_Name' => 'hsl', 'Origin_Node' => 'TQTHSL1:HSL:MQ', 'Reporting_MQ_Manager_Name' => 'TQTHSL1', 'Event_Host_Name' => 'hsl', 'Application_Identifier' => '', 'Event_MQ_Manager_Name' => 'TQTHSL1', } } }; Got paramsall: HASH(0x207f2ed8) Got paramsout:
Now it is obvious that all those <ROW> elements are writing over the top of the same hash key but how on earth do I go about fixing it ? I can think of the ugly option of clunking the raw XML to replace ROW with ROW$i++ then pass it on the thje parser, but I know that is a sin for which I will face eternal purgatory. Where should I look to fix this properly ?

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Comment on XML Parser clobbering Multiple occurances of element
Select or Download Code
Re: XML Parser clobbering Multiple occurances of element
by GrandFather (Cardinal) on Aug 12, 2005 at 12:25 UTC

    What does your parser code look like? Which parser are you using?


    Perl is Huffman encoded by design.

      Hi GrandFather

      SOAP::Lite calls the parser for me when I call the result method on the object that made the SOAP call. From the hint anonymonk gave me I think there may be Perls of wisdom in the SOAP::Lite example code.

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!
Re: XML Parser clobbering Multiple occurances of element
by Anonymous Monk on Aug 12, 2005 at 12:26 UTC
    XML::Parser isn't responsible.
    Now it is obvious that all those <ROW> elements are writing over the top of the same hash key but how on earth do I go about fixing it ?
    check the examples (RTFM)

      Thanks for the help, at least I can move on from the XML::Parser docs which I spent most of the afternoon reading :( ah well a bit more knowledge never goes amiss.

      Which examples should I head for now ? My problem is really that there is so much documentation and I can not fathom which layer my problem stems from, all the way from Expat itself through to SOAP::Lite, they all come with piles of examples and hundred of helpful web pages to be googled. Then I started to fear I may have to work with DTD or xmlns.

      I will guess the SOAP examples, if I am wrong a pointer elswhere would be most welcome.

      Thanks and Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!
Re: XML Parser clobbering Multiple occurances of element
by gellyfish (Monsignor) on Aug 12, 2005 at 14:04 UTC

    Rather than accessing the result() of the SOAP 'method' call you need to access the SOAP::SOM object return from the method - you should see the section entitled ITERATING OVER AN ARRAY in the SOAP::SOM manpage of the latest SOAP::Lite

    /J\

Re: XML Parser clobbering Multiple occurances of element
by Tanktalus (Canon) on Aug 12, 2005 at 14:09 UTC

    A brief check of SOAP::Lite's documentation shows that you probably want to call paramsout in list context: my @rows = $soap->paramsout(), or you want to use valueof with an XPath for each row - e.g., //ROW[0], //ROW[1], and //ROW[2]. Looking at all this, I'm thinking it'd be easier/more straight forward to take the XML and pump it through XML::Twig to get a reasonable object-oriented output rather than the hashes - XML::Twig handles so-called "duplicate" entries in a very straight-forward manner, IMO.

      Hi Tanktalus

      I already tried paramsout and paramsall in list context with a  print "paramsall: ", (join ", ", $response->paramsall) which just shows the one solitary object, the same that result returns. I am now going to take a look at XML::Twig and gellyfish's hint to look at the SOAP::SOM docs.

      Thanks for the help,
      R.

      Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://483255]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-09-20 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls