tried using XML::LibXML as well but I can't get it to return a valid data structureYou can use XML::LibXML but because of the xmlns="http://xmlns.sony.net..." in the TMSMessage tag you have to perform some namespace trickery. By referring to this node I came up with this snippet which may be of help:
Output using your sample XML:my $text = q|<?xml version="1.0" encoding="UTF-8"?> <TMSMessage xmlns="http://xmlns.sony.net/d-cinema/tms-api/v1"> <MessageHeader> <Id>-1</Id> <Type>ListPerformances</Type> ...etc </TMSMessage>|; my $doc = XML::LibXML->load_xml(string => $text); my $xc = XML::LibXML::XPathContext->new( $doc->documentElement() ); $xc->registerNs( pfx => 'http://xmlns.sony.net/d-cinema/tms-api/v1' ); my @events = $xc->findnodes('//pfx:EventInfo'); for my $event (@events) { my $id = $xc->findvalue('pfx:EventId', $event); print "EventId: $id\n"; my @packs = $xc->findnodes('pfx:PreshowPackList/pfx:PreshowPack', +$event); if ( not @packs ) { print "No Packs\n"; next; } for my $pack (@packs) { my $pack_id = $xc->findvalue('pfx:PackId', $pack) || "No PackI +d"; print "PackId: $pack_id\n"; } }
EventId: 2015060400000157 No Packs EventId: 2015060400000164 No Packs EventId: 2015060200000562 PackId: b863a576-d8a3-4f5d-92a7-b66f876f6d7c PackId: No PackId PackId: a55164d0-faa7-4c7c-a688-ed36011add95 EventId: 2015060200000563 PackId: 760eb073-81f8-45cb-8553-484c5cecb740 PackId: No PackId PackId: a55164d0-faa7-4c7c-a688-ed36011add95
In reply to Re: XML Parsing Problems
by tangent
in thread XML Parsing Problems
by taralon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |