in reply to Re: Extracting tagged data from a XML file
in thread Extracting tagged data from a XML file

The problem is still the same, it reads both the one taged "<IPAddress>" and the ones taged "<NEIGHBOURIPAddress>".
148.192.116.253
148.192.116.253
148.192.116.253
148.192.116.253
148.192.116.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.137.253
148.192.63.249
148.192.63.249
148.192.63.249
148.192.63.249
148.192.63.249
148.192.63.249
148.192.63.249
148.192.63.249
148.192.63.249
148.192.63.249
this is what sonme of them look like! many are the same. :-(
  • Comment on Re: Extracting tagged data from a XML file

Replies are listed 'Best First'.
Re^2: Extracting tagged data from a XML file
by davorg (Chancellor) on Aug 31, 2004 at 10:59 UTC

    It looks like that's what you asked for. I'm not sure what the problem is.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      The problem is that i need every IP only once. (Sorry if i didn't say that before). So i only need to get the IPAddress and not also the NEIGHBOURIPAddress, bacause then i have everything only once.

        If you ever need to get unique values in Perl then you should think about using a hash.

        use XML::XPath; my $xp = XML::XPath->new(filename => '/path/to/file'); my %seen; foreach ('IP-ADDRESS', 'IP-NEIGHBOUR') { foreach my $ip ($xp->findnodes("//$_")) { my $addr = $ip->findvalue('.'); print "$addr\n" unless $seen{$addr}++; } }
        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Re^2: Extracting tagged data from a XML file
by theroninwins (Friar) on Aug 31, 2004 at 13:26 UTC
    ok here is another idea I had:

    # use XML::Dumper; open (XMLINPUT, "e:/topo.xml") or (print "Die XML Datei konnte nicht geöffnet werden!!\n". "Bitte Pfad und Dateiname mit Slashs angeben!!". "\nz.B. c:/data1.xml\n" and open (MACERROR, ">XMLError.err") and print MACERROR "Die XML Datei konnte nicht geöffnet werden!!\n +". "Bitte Pfad und Dateiname mit Slashs angeben!!". "\nz.B. c:/data1.xml\n" and close MACERROR and exit); # Zeiger erzeugen $zeiger_xml = new XML::Dumper->xml2pl(join("",<XMLINPUT>)); $zeiger_data = \@{$zeiger_xml->{'Data'}}; close XMLINPUT; open (CACHENEU, ">ips2.txt"); close CACHENEU; foreach $z_device (@{$zeiger_xml->{'Device'}}) { #if ( $z_device->{'SystemDescription'} =~ m/Version 12.0 +\(5\)/ #and $z_device->{'SystemDescription'} =~ m/C2900/ #and $z_device->{'SystemDescription'} !~ m/WS/) #{ open (CACHENEU, ">>ips2.txt"); foreach $z_add (@{$z_device->{'DeviceName'}}) { %PortHash = ( $z_device->{'DeviceName'} => $z_ip->{'IPAddr +ess'} ); printf CACHENEU ("%s\t\t%s\n",%PortHash); } close CACHENEU; #} } print "\nfertig Portliste erstellen!!\n" ;


    and this is the File I have to read from:

    <?xml version="1.0" encoding="UTF-8" ?> - <CMData> <CMServer>S03</CMServer> <CreatedAt>Tue Aug 24 09:09:41 GMT+02:00 2004</CreatedAt> <SchemaVersion>1.0</SchemaVersion> <Heading>Topology Data</Heading> - <Layer2Details> - <Device> <DeviceName>LWL-H91-CW-4-5-4</DeviceName> <IPAddress>148.192.59.254</IPAddress> <DeviceState>Reachable</DeviceState> <DeviceType>C2950G-24</DeviceType> - <Neighbors> - <Neighbor> <NeighborIPAddress>148.192.22.22</NeighborIPAddress> <NeighborDeviceType>C6506</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Gi0/2</LocalPort> <RemotePort>3/3</RemotePort> </Neighbor>


    Any idea on where I am mistaking??