Click here to get back home

perl xml check for element closure

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
perl xml check for element closure inetquestion 11-18-2006
Posted by inetquestion on November 18, 2006, 9:26 pm
Please log in for more thread options


I'm interested in writing a perl script that checks an xml document for
proper element closure only. There is no dtd associated, so this is
really the only type validation I could think of... Is there an easy
way to do this via perl? All I'm looking for is a simple 0 or 1 return
code.

Regards,

-Inet


Posted by inetquestion on November 18, 2006, 9:41 pm
Please log in for more thread options


I just found the code below which appears to be exactly what I was
looking for... As soon as I get back to my home pc I'll give it a
shot.

-Inet

----------------






use XML::Parser;

my $xmlfile = shift @ARGV; # the file to parse

# initialize parser object and parse the string
my $parser = XML::Parser->new( ErrorContext => 2 );
eval { $parser->parsefile( $xmlfile ); };

# report any error that stopped parsing, or announce success
if( $@ ) {
$@ =~ s/at \/.*?$//s; # remove module line number
print STDERR "\nERROR in '$xmlfile':\n$@\n";
} else {
print STDERR "'$xmlfile' is well-formed\n";
}


Similar ThreadsPosted
manually expire an element in Memoize (also on comp.lang.perl.misc) February 14, 2007, 5:52 pm
Net::SSH::Perl - Corrupted check bytes February 8, 2006, 9:33 am
How to text in HTML::Element October 23, 2004, 7:31 pm
Extracting value from data within an element. November 30, 2005, 5:26 am
How to *modify* text in HTML::Element October 23, 2004, 8:16 pm
XML::LibXSLT element tags stripped out of transformation March 21, 2005, 6:32 pm
HTML::Element->right/->look_down lose, I need to walk the tree June 20, 2005, 9:56 am
check response with mod_perl October 22, 2004, 11:23 am
how to check for existenceof XML tags with XML::Simple? January 29, 2005, 12:45 pm
Email address syntax check? December 2, 2006, 2:58 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap