>>>>> ""Beginner"" == "Beginner"  <[EMAIL PROTECTED]> writes:

"Beginner"> I have been trying to use XML::Simple and I had a go with 
XML::Smart 
"Beginner"> but I haven't been able to get the results I want.

I'd use XML::LibXML, with an XPath expression, as follows.  I'm demoing by
deleting the one that starts "BJPU", but replace that with your "0000" and
you're all set.

Note that the XPATH says "find any address node that contains a code node
whose text begins with BJPU".  And those are the ones we want to delete.

    #!/usr/bin/env perl
    use strict;

    use XML::LibXML;
    my $parser = XML::LibXML->new;
    my $doc = $parser->parse_fh(\*DATA);

    my @bad = $doc->findnodes(q{//address[.//code[starts-with(., "BJPU")]]});

    for (@bad) {
      $_->unbindNode;               # delete it!
    }

    print $doc->toString(1);

    __END__
    <?xml version = "1.0" encoding= "utf-8"?>
    <addresses>
            <address number="2577">
                    <code>BJPPHO00</code>
                    <record_type>client</record_type>
                    <address_type>shipping</address_type>
                    <Postcode>EC1Y 4RX</Postcode>
                    <Country>GBR</Country>
                    <lines>
                            <line>PIGEON MEDIA</line>
                            <line>HAYMARKET HOUSE</line>
                            <line>28-29 HAYMARKET</line>
                            <line>LONDON</line>
                            <lines>EC1Y 4RX</lines>
                    </lines>
            </address>
            <address number="2578">
                    <code>BJPUBL00</code>
                    <record_type>client</record_type>
                    <address_type>shipping</address_type>
                    <Postcode>SU1V 0AQ</Postcode>
                    <Country>GBR</Country>
                    <lines>
                            <line>RIVER HOUSE</line>
                            <line>12-14 BERRY STREET</line>
                            <line>SURREY</line>
                            <line>SU1V 0AQ</line>
                    </lines>
            </address>
    </addresses>

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to