Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: XML Parsing from URL - XML::Twig and infinite stream

by Discipulus (Canon)
on Jul 03, 2015 at 12:18 UTC ( [id://1133088]=note: print w/replies, xml ) Need Help??


in reply to Re^3: XML Parsing from URL - XML::Twig and infinite stream
in thread SOLVED: XML Parsing from URL

maybe someting ugly as (modified the data to get rid of the --boundary thing):
#!/usr/bin/perl use strict; use warnings; use XML::Twig; $|++; open my $fh,'<','xmlstream.xml' or die; while (<DATA>) { chomp; if ($_ =~/Content-Length: (\d+)/){ my $len = $1; my $xml; my $read = read (DATA,$xml,$len,0); print "read: tried $len got $read: [$xml]\n"; my $t= XML::Twig->new( pretty_print => 'indented', twig_handlers => { 'ipAddress'=>sub{print "\t\tIP ADDRESS:\t",$ +_[1]->text,"\n"; } } ); $t->parse($xml); } } __DATA__ Content-Type: application/xml; charset="UTF-8" Content-Length: 478 <EventNotificationAlert version="1.0" xmlns="http://www.hikvision.com/ +ver10/XMLSchema"> <ipAddress>10.1.10.23</ipAddress> <portNo>80</portNo> <protocol>HTTP</protocol> <macAddress>c4:2f:90:00:00:00</macAddress> <channelID>1</channelID> <dateTime>2015-06-24T19:37:22--8:00</dateTime> <activePostCount>0</activePostCount> <eventType>videoloss</eventType> <eventState>inactive</eventState> <eventDescription>videoloss alarm</eventDescription> </EventNotificationAlert> Content-Type: application/xml; charset="UTF-8" Content-Length: 514 <EventNotificationAlert version="1.0" xmlns="http://www.hikvision.com/ +ver10/XMLSchema"> <ipAddress>10.1.10.23</ipAddress> <portNo>80</portNo> <protocol>HTTP</protocol> <macAddress>c4:2f:90:00:00:00</macAddress> <channelID>1</channelID> <dateTime>2015-06-24T19:37:22--8:00</dateTime> <activePostCount>1</activePostCount> <eventType>VMD</eventType> <eventState>active</eventState> <eventDescription>Motion alarm</eventDescription> <DetectionRegionList> </DetectionRegionList> </EventNotificationAlert>


HtH
L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-18 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found