#!/usr/bin/perl #use warnings; #use strict; use XML::DOM; use LWP::UserAgent; use LWP::Simple; open( CONTACTS, "+parse( \*CONTACTS ); printlist( $document ); seek( CONTACTS, 0, 0 ); truncate( CONTACTS, 0 ); $document->print( \*CONTACTS ); sub printlist { my $document = shift; my $root = $document->getElementsByTagName( "ResultSet" )->item( 0 ); my $contactList = $root->getChildNodes(); for my $i ( 1 .. $contactList->getLength - 1 ) { my $contact = $contactList->item( $i ); next unless ( $contact->getNodeName eq 'Result' ); my $Title = $contact->getElementsByTagName( "Title" ); my $title = $Title->item( 0 )->getChildAtIndex( 0 )->getData(); my $Address = $contact->getElementsByTagName( "Address" ); my $address = $Address->item( 0 )->getChildAtIndex( 0 )->getData(); my $City = $contact->getElementsByTagName( "City" ); my $city = $City->item( 0 )->getChildAtIndex( 0 )->getData(); my $State = $contact->getElementsByTagName( "State" ); my $state = $State->item( 0 )->getChildAtIndex( 0 )->getData(); my $Phone = $contact->getElementsByTagName( "Phone" ); my $phone = $Phone->item( 0 )->getChildAtIndex( 0 )->getData(); my $Lat = $contact->getElementsByTagName( "Latitude" ); my $lat = $Lat->item( 0 )->getChildAtIndex( 0 )->getData(); my $Long = $contact->getElementsByTagName( "Longitude" ); my $long = $Long->item( 0 )->getChildAtIndex( 0 )->getData(); $BusUrl = $contact->getElementsByTagName( "BusinessUrl" ); $bus_url = $BusUrl->item( 0 )->getChildAtIndex( 0 )->getData(); # change phone number format $phone =~ s/\(//; $phone =~ s/\)//; $phone =~ s/-//; $phone =~ s/\s+//; print( "$title $address $city $state $phone $lat $long $bus_url\n" ); } } #### My Real Estate Agent
74738 Jones Ave
Leesburg VA (703) 723-1113 84848894 23232 http://www.mcmmcmmc.net
Johns Bakery
8484399 heewis Dr
Sterling VA (703) 723-1114 8383883 213123
Kevins flooring
84848484 kevin drive
Fairfax VA (703) 723-1115 2321321 123 http://www.nothing.com
##
## Can't call method "getData" on an undefined value at parse_xml.pl line 74. #### if( $#BusUrl < 0 ) if( length $contact->getElementsByTagName( "BusinessUrl" )) if ($BusUrl) if (defined ( $BusUrl )) if (defined ( $contact->getElementsByTagName( "BusinessUrl" ))) if ($BusUrl) if ($BusUrl->item( 0 )->getChildAtIndex( 0 )->getLength)