Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > perl xml check for element closure
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 14th April 04:34
inetquestion
External User
 
Posts: 1
Default perl xml check for element closure



I'm interested in writing a perl script that checks an xml do***ent 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
  Reply With Quote


  sponsored links


2 14th April 04:34
inetquestion
External User
 
Posts: 1
Default perl xml check for element closure



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";
}
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666