1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
use 5.010; use strict; use warnings; my $serverresponse = '<pp ppn="1" relType="Dynamic" uid="3" ipei="00435709475" ac="10551" s="Yes" uak="328497hfdfh8" encrypt="1" capMessaging="1" capMessagingForInternalUse="0" capEnhLocating="1" capBluetooth="1" ethAddr="00:30:42:0F:F2:7D" hwType="630d" />'; $serverresponse =~ s|[\r\n]||g; # falls auf mehere Zeilen dann Zeilenende rauslöschen my (@lines) = $serverresponse =~ m|\<pp\s+([^>]+)\s+/>|g; my %hash = # 4. dann ists ein Hash map { (split /=/) } # 3. Wertepaare am = auftrennen map { s/"//g;(split /\s+/) } # 1. " rauslöschen, 2. Wertepaare am Leerzeichen austrennen @lines; # für Zeilen #say "$_=>$hash{$_}" for keys %hash; # nur zum Test wenn gewünscht ;) say "$_ ist $hash{$_}" for qw(uid ppn ethAddr hwType);
1 2 3 4 5 6 7 8
use XML::LibXML; my $p = XML::LibXML->new; my $doc = $p->parse_string($xml); my $root = $doc->documentElement; my ($pp) = $root->findnodes("pp"); for my $field ( qw/ uid ppn ethAddr hwType /) { say $pp->getAttribute($field) }
<GetPPUserResp><user uid="2" relType="Unbound" ppn="0" name="Test User" num="3461" hierarchy1="Physics" hierarchy2="Dr h.c." addId="" sipAuthId="3461" sipPw="M6WPCUL+3LLfXPuFV6TqsuYGUtosYcL8zWkyrUgyEQTJh4mPJcOWvLy+2ivcONn0NEumLq0rRSk6HZ5AiuqiNw==" sosNum="" manDownNum="" voiceboxNum="" pin="PwJvjDU/iECiv1d3VjnMN6TkCpWJM2Y9IgIxw5kXNuc7cMD8OVgahuaq9ItzG3eGGRd4mZUug+IDKHWDf0YLtw==" lang="English" forwardState="Off" forwardDest="" forwardTime="0" holdRingBackTime="3" callWaitingDisabled="0" trackingActive="0" locRight="0" locatable="1" msgRight="0" sendVcardRight="0" recvVcardRight="0" keepLocalPB="0" vip="0" external="0" BTlocatable="1" BTsensitivity="high" conferenceServerType="Global" conferenceServerURI="" monitoringMode="Off" HAS="Unknown" HSS="Unknown" HRS="Unknown" HCS="Unknown" SRS="Unknown" SCS="Unknown" CDS="Unknown" HBS="Unknown" BTS="Unknown" SWS="Unknown" CUS="Unknown" /></GetPPUserResp>
1
2
3
4
$doc = $myObj->parse_string($Users); # Search through the XMl-Stuff
print "This is $doc\n";
$root = $doc->documentElement;
($PPN) = $root->findnodes("user"); # Find the keyword
1
2
3
4
5
6
:1: parser error : Document is empty
^
:1: parser error : Start tag expected, '<' not found
^
<?xml version="1.0" encoding="UTF-8"?><GetPPUserResp><user uid="2" relType="Unbound" ppn="0" name="Albert Einstein" num="3461" hierarchy1="Physics" hierarchy2="Dr h.c." addId="" sipAuthId="3461" sipPw="jIsp7DBnhh2ghUjQu2sL1Jeu3yjiSVpTBVY00cChFuJPyeEcCUP2pskEWbNfiFdwoe2KBX9SI8QZ0sVdn6n+Cw==" sosNum="" manDownNum="" voiceboxNum="" pin="UWovU0hfxB9KFM7KkQfiz7cRO2LCTvACD4KGuaSzQfGyI7d0jOUipzwFnijqAGPPpksRVQlla15ertMT8bZv9w==" lang="English" forwardState="Off" forwardDest="" forwardTime="0" holdRingBackTime="3" callWaitingDisabled="0" trackingActive="0" locRight="0" locatable="1" msgRight="0" sendVcardRight="0" recvVcardRight="0" keepLocalPB="0" vip="0" external="0" BTlocatable="1" BTsensitivity="high" conferenceServerType="Global" conferenceServerURI="" monitoringMode="Off" HAS="Unknown" HSS="Unknown" HRS="Unknown" HCS="Unknown" SRS="Unknown" SCS="Unknown" CDS="Unknown" HBS="Unknown" BTS="Unknown" SWS="Unknown" CUS="Unknown" /></GetPPUserResp>
1
2
:1: parser error : Start tag expected, '<' not found
<?xml version="1.0" encoding="UTF-8"?>
$Users = q|hier das XML|;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
my $xml = q{<ServerResp><pp ppn="1" relType="Dynamic" uid="3" ipei="00435709475" ac="10551" s="Yes" uak="328497hfdfh8" encrypt="1" } . q{capMessaging="1" capMessagingForInternalUse="0" capEnhLocating="1" capBluetooth="1" ethAddr="00:30:42:0F:F2:7D" hwType="630d" /></ServerResp>}; use XML::LibXML; my $p = XML::LibXML->new; my $doc = $p->parse_string($xml); my $root = $doc->documentElement; my ($pp) = $root->findnodes("pp"); for my $field ( qw/ uid ppn ethAddr hwType /) { say $pp->getAttribute($field) } __END__ 3 1 00:30:42:0F:F2:7D 630d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl -w
# Version 0.3
# Date Apr 2013
########################################
# Modules
use strict; # parameter Definition before use them
use XML::LibXML; # Libary for XML
use IO::Socket::SSL; # TCP/IP sockets
#######################################
# Paramet Definition
my $host = '192.168.2.101'; # Test OMM
my $port = 12622; # OpenMobility-Manager-Port
my $seqid = "4711"; # nice to have
my $uname = "operator";
my $pw = "LoginPW";
my $protoVer = 41; # OM AXI Protocol Version -> unimportant
my $timer = 1;
my ($basicInfo,$OM_AXI_Input,$UserNotes,$myResponse,$Users); # Basic information -> Standard Response
my ($RecAmount,$firstPPN);
my @Values;
my $socket = IO::Socket::SSL->new(PeerAddr=>$host,PeerPort=>$port,Timeout=>$timer);
# XML Parameter
my $myObj = XML::LibXML->new;
my ($preLine,$XMLin,$doc,$root,$PPN,$field);
my ($child,$at,$na,$va);
my (@kids,@atts);
###########################
# main programm
system("clear");
##################################
# OMM Axi
$UserNotes = qq{<GetPPUser uid="2"/>\0};
$socket -> print(qq{<Open seq="$seqid" protocolVersion=$protoVer username="$uname" password="$pw"/>\0}); # Send Authentication
$basicInfo = $socket->readline();
$socket -> print($UserNotes);
$Users = $socket->readline();
############
# XML Parsing
##################
$preLine = '<?xml version="1.0" encoding="UTF-8"?>';
$XMLin = $preLine.$Users;
print "$XMLin \n";
$doc = $myObj->parse_string($XMLin); # Search through the XMl-Stuff
$root = $doc->documentElement;
($PPN) = $doc->findnodes("user"); # Find the keyword
for $field ( qw{uid ppn ethAddr hwType}) {
say $PPN->getAttribute($field)
}
<?xml version="1.0" encoding="UTF-8"?><GetPPUserResp><user uid="2" relType="Unbound" ppn="0" name="Albert Einstein" num="3461" hierarchy1="Physics" hierarchy2="Dr h.c." addId="" sipAuthId="3461" sipPw="M0ziPLBb9ntxkx68hJ8920lcarx0x0SX5Lvcs5Pzi4TQeThP/vKsKEx1lLK9tiKc3FxREhGRpkUUIjY+FkmRag==" sosNum="" manDownNum="" voiceboxNum="" pin="ZkDJaRCnZgC6IxEaB4T2hm6cOrbwgfErC8DACJt5IVFqcfexe8ilupZYYg8QdBQMl6DHVEWlowooZSGYrTbFFw==" lang="English" forwardState="Off" forwardDest="" forwardTime="0" holdRingBackTime="3" callWaitingDisabled="0" trackingActive="0" locRight="0" locatable="1" msgRight="0" sendVcardRight="0" recvVcardRight="0" keepLocalPB="0" vip="0" external="0" BTlocatable="1" BTsensitivity="high" conferenceServerType="Global" conferenceServerURI="" monitoringMode="Off" HAS="Unknown" HSS="Unknown" HRS="Unknown" HCS="Unknown" SRS="Unknown" SCS="Unknown" CDS="Unknown" HBS="Unknown" BTS="Unknown" SWS="Unknown" CUS="Unknown" /></GetPPUserResp>
2013-04-05T07:19:00 cohamaHallo zusammen,
Code: (dl )1
2
3$doc = $myObj->parse_string($XMLin); # Search through the XMl-Stuff
$root = $doc->documentElement;
($PPN) = $doc->findnodes("user"); # Find the keyword
$doc
$root
Quote$VAR1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\0<GetPPUserResp><user uid=\"2\" relType=\"Unbound\" ppn=\"0\" name=\"Albert Einstein\" num=\"3461\" hierarchy1=\"Physics\" hierarchy2=\"Dr h.c.\" addId=\"\" sipAuthId=\"3461\" sipPw=\"osD3Ec0aAL9TK3rM1woviG/UMu8ZD1ICw95QJBJnYWi5uVXwE8ankHqRQ9I9GjwL4dfCaaVq0bE7I47qH+/7gA==\" sosNum=\"\" manDownNum=\"\" voiceboxNum=\"\" pin=\"Hho9YrIPHoQXWgRRJVboTdJw2RrhLllIluTz9+vuvyLOGsCRY/E65QVL42PleUTmbwRCNDT43MDoLqJm0jZa2Q==\" lang=\"English\" forwardState=\"Off\" forwardDest=\"\" forwardTime=\"0\" holdRingBackTime=\"3\" callWaitingDisabled=\"0\" trackingActive=\"0\" locRight=\"0\" locatable=\"1\" msgRight=\"0\" sendVcardRight=\"0\" recvVcardRight=\"0\" keepLocalPB=\"0\" vip=\"0\" external=\"0\" BTlocatable=\"1\" BTsensitivity=\"high\" conferenceServerType=\"Global\" conferenceServerURI=\"\" monitoringMode=\"Off\" HAS=\"Unknown\" HSS=\"Unknown\" HRS=\"Unknown\" HCS=\"Unknown\" SRS=\"Unknown\" SCS=\"Unknown\" CDS=\"Unknown\" HBS=\"Unknown\" BTS=\"Unknown\" SWS=\"Unknown\" CUS=\"Unknown\" /></GetPPUserResp>\n";