Hi Monks!
I have XML files in a directory and I am trying to make things very simple by just opening these files and check the existence of the first and last element - <order> and </order> , to make sure I don't get any bad XML in my other Perl code, and eventually delete the bad formatted XML file(s), but having problems trying to match it in my regular expression, can anyone help me with that?

my $xml_dir = "c://apache//htdocs//xml"; opendir(DIR, $xml_dir); my @files = grep { /\.xml$/ } readdir(DIR); closedir(DIR); foreach my $file (@files) { if($file =~/<order>(.*)<\/order>/g){ print "FILE::: $file\n"; } }

XML Sample File 1:
<order> <customer> <name>Coyote, Ltd.</name> <shipping_info> <address>1313 Desert Road</address> <city>Nowheresville</city> <state>AZ</state> <zip>90210</zip> </shipping_info> </customer> <item> <product id="1111">Acme Rocket Jet Pack</product> <quantity type="each">1</quantity> </item> <item> <product id="2222">Roadrunner Chow</product> <quantity type="bag">10</quantity> </item> </order>


XML Sample File 2 - This file is not valid:
<order> <customer> <name>Coyote, Ltd.</name> <shipping_info> <address>1313 Desert Road</address> <city>Nowheresville</city> <state>AZ</state> <zip>90210</zip> </shipping_info> </customer> <item> <product id="1111">Acme Rocket Jet Pack</product> <quantity type="each">1</quantity> </item> <item> <product id="2222">Roadrunner Chow</product> <quantity type="bag">10</quantity> </item>


Thanks!!!

In reply to Regular Expression XML Searching Help by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.