Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: XML validating (no DTD)

by iburrell (Chaplain)
on Sep 02, 2004 at 16:47 UTC ( [id://387992] : note . print w/replies, xml ) Need Help??


in reply to XML validating (no DTD)

I don't see any DTD declared in the XML or the code. If you don't have a schema to validate against, you can't validate an XML document. Checking for well-formed is different, and something most parsers should report on. XML::Checker::Parser looks like it only validates against DTDs declared in the document.

You can also validate against XML Schema or RELAX NG. I don't know of any pure Perl code for those, but calling external programs and libraries work well.

Replies are listed 'Best First'.
Re^2: XML validating (no DTD)
by 2ge (Scribe) on Sep 02, 2004 at 21:33 UTC
    Hi

    I just found the solution on perlmonks, it is so easy:
    use XML::Parser; my $p = XML::Parser->new; my $file = 'data.xml'; eval { $p->parsefile($file) }; if ($@) { print 'XML is not well formed'; } else { print 'XML is well formed'; }


    Ofcoure, I can't validate XML, if I don't have DTD, I can check it if it is well formed, sorry for mistake.