Hi, I have to do some sanity checks on a large xml file of addresses (snip below). I have been using XML::LibXML and seem to have started ok but I am struggling to navigate around a record.
In the sample date below your'll see some addresses with "DO NOT..." in. I can locate them easily enough but I am struggling to navigate back up the DOM to access the code so I can record the code with faulty addresses. Here my effort. Can anyone help me either to move backup up to the right element node or catch the code node before I begin to loop through the address line(s). TIA, Dp. ======= My Effort ========== #!/usr/bin/perl use strict; use warnings; use XML::LibXML; my $file = 'ADDRESS.XML'; open(FH,$file) or die "Can't open file $file: $!\n"; my $parser = XML::LibXML->new; my $doc = $parser->parse_fh(\*FH); my @results = $doc->findnodes('//address'); foreach my $i (@results) { my @addlines = $i->findnodes('//line'); foreach my $l (@addlines) { if ($l->string_value =~ /\s+NOT\s+/) { my $p = $i->nodePath; $p .= '/code'; print $p->nodeValue,"\t"; print $l->string_value, "\t"; print $l->string_value, "\n"; } } } ============================= =========== Sample Data ========== <?xml version = "1.0" encoding= "utf-8"?> ...snip <address number="1016"> <code>B679OOO00</code> <record_type>client</record_type> <address_type>shipping</address_type> <Postcode></Postcode> <Country>GBR</Country> <lines> <line>DO NOT USE THIS CODE</line> </lines> </address> <address number="1014"> <code>P982LUS00</code> <record_type>client</record_type> <address_type>shipping</address_type> <Postcode>HR2 0AU</Postcode> <Country>GBR</Country> <lines> <line>UPPER HOUSE FARM</line> <line>BACTON</line> <line>ESSEX</line> <line>EX2 0AU</line> </lines> </address> <address number="1333"> <code>A234ULE00</code> <record_type>client</record_type> <address_type>shipping</address_type> <Postcode></Postcode> <Country>AND</Country> <lines> <line>QUEENS HOUSE</line> <line>1 BUCKINGHAM PALACE</line> <line>LONDON WC2H</line> <line>****NOT AT THIS ADDRESS ANY MORE.</line> <line>***************</line> </lines> </address> <address number="1018"> <code>A&MPUB00</code> <record_type>client</record_type> <address_type>shipping</address_type> <Postcode>PO19 8SQ</Postcode> <Country>GBR</Country> <lines> <line>THE ATRIUM</line> <line>SOUTHERN GATE</line> <line>CHICHESTER</line> <line>SUSSEX</line> <line>PO19 8SQ</line> </lines> </address> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/