in reply to using XML::LIbXML to validate against a dtd and retrieve any errors therein

This is untested, but try:
print XML::LibXML->get_last_error;
Or alternatively, use the exception throwing form of validation:
eval { $doc->validate; }; if ($@) { print "Doc not valid: $@\n"; } else { print "Doc valid\n"; }

Replies are listed 'Best First'.
Re: Re: using XML::LIbXML to validate against a dtd and retrieve any errors therein
by drfrog (Deacon) on May 20, 2002 at 20:14 UTC
    hello
    i figured this out!
    while i couldnt find anything about the validate or
    get_last _error functions i did manage to get code to werk!

    thanks matt!

    here is a sample xml:
    <?xml version="1.0"?> <!DOCTYPE roots SYSTEM 'dtd.dtd'> <roots> <child1 attrib="3"></child1> <child2></child2> <child3/> </roots>
    the dtd:
    <!ELEMENT roots (child1,child2,child3)> <!ELEMENT child1 (#PCDATA)> <!ATTLIST child1 attrib CDATA #REQUIRED> <!ELEMENT child2 EMPTY> <!ELEMENT child3 (#PCDATA)>
    and the perl script:
    #!/usr/bin/perl use strict; use XML::LibXML; my $parser = XML::LibXML->new(); $parser->validation(1); eval {print "xml is valid=".$parser->parse_file('xml.xml')->is_valid +."\n"; }; if ($@) { print "dtd not valid: $@\n";} else { print "dtd valid\n";}

    hope this helps anyone else in the future