Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

I am trying to validate an XML using a DTD file. I have captured the output but I don't know what line/what word, etc. is causing the validation to fail. Here is the code:

my ($dtd_file) = @_; my $file_target = "$main::args{xml_dir}/$main::args{file}"; my $dtd_target = "$main::args{xml_dir}/$dtd_file"; my $dtd = XML::LibXML::Dtd->new("", $dtd_target); my $parser = XML::LibXML->new(); $parser->validation(1); my $document; if (! -f $file_target) { print "Cannot find required file: $file_target\n"; exit(0); } if (! -f "$dtd_target") { print "Cannot find required file: $dtd_target\n"; exit(0); } eval { $document = $parser->parse_file($file_target); $document->validate($dtd_file); }; if ($@) { print "XML not valid because of $@ !\n"; }

If I use this code I get the error message:
XML not valid because of is_valid: argument must be a DTD object at ./ line 146.

Line 146 is the line were $document->validate($dtd_file) is called. Stephen

2003-06-07 edit ybiC: <code> tags

In reply to Gathering more verbose output from XML file validation by storri

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.