Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl regular expression

perl script for tracing XML tags from XML file

         

srinivasan

7:47 am on Oct 1, 2008 (gmt 0)

10+ Year Member



Iam very new to perl script,
I have a task to do with perl script for finding XML elements.

The task is as below:

XML file:

<article>
<section>
<number>1</number>
<issue></issue>
<year></year>
<b></b>
</section>
<chapter>
<p>hai this is sample<b>for u</b><i></i><sup></sup>
</p>
</chapter>
</article>

Now the task is i need to write a perl script to find and throw the error list of empty tags that is present in between <chapter> and </chapter>, i dont wan to highlight the error which is in between <section> and </section>.

I had developed a script as belw but it is highlighting all the empty tags even from <section> area.

The code is as below:

$cnt=1;
while($content=~/<(sup¦inf¦i¦b)><\/\1>/ig)
{
print outfile "Error ".$cnt."Empty Tag <". $1 . "> Found"."\n";
$cnt++;
}

can any one help in this regard?

phranque

10:03 pm on Oct 1, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], srinivasan!

first use a regular expression to extract the contents of the chapter tag and put the string into the $content variable.
then use your code snippet to report the empty tags.