I have looked high and low for a simple way to validate (not merely to check for well-formedness) an XML v 1.0 document against its dtd. I have looked through this site and am aware of merlyn's previous advice to use XML::Checker.

The problem is that the XML::Checker module is not well documented and the sample code throws the following exception:Can't call method "Start" on an undefined value at /usr/lib/perl5/site_perl/5.6.0/XML/Checker/Parser.pm line 194. Here's the code:
#!/usr/bin/perl -w use XML::Checker::Parser; my $parser = new XML::Checker::Parser (); die "Can't create object" unless (ref $parser); eval { local $XML::Checker::FAIL = \&my_fail; $parser->parsefile ("/usr/local/pd/ADS/index.xml"); }; if ($@) { # Either XML::Parser (expat) threw an exception or my_fail() died. #... your error handling code here ... print "you suck!\ngo eat a bone!\n"; } # Throws an exception (with die) when an error is encountered, this # will stop the parsing process. # Don't die if a warning or info message is encountered, just print a +message. sub my_fail { my $code = shift; die XML::Checker::error_string ($code, @_) if $code < 200; XML::Checker::print_error ($code, @_); }
and here's the DTD I am trying to validate against:
<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT PDList (PD*)> <!ATTLIST PDList RunDateTime CDATA #REQUIRED> <!ELEMENT PD ( PayPlan, Grade, OccupationalSeries, NASAPositionTitle, OPMPositionTitle, FileName, NASALocation, DutyLocation, OrganizationalCode, NASAClassCode, SourceSystem)> <!ATTLIST PD PDNumber CDATA #REQUIRED> <!ELEMENT PayPlan (#PCDATA)> <!ELEMENT Grade (#PCDATA)> <!ELEMENT OccupationalSeries (#PCDATA)> <!ELEMENT NASAPositionTitle (#PCDATA)> <!ELEMENT OPMPositionTitle (#PCDATA)> <!ELEMENT FileName (#PCDATA)> <!ELEMENT NASALocation (#PCDATA)> <!ELEMENT DutyLocation (#PCDATA)> <!ELEMENT OrganizationalCode (#PCDATA)> <!ELEMENT NASAClassCode (#PCDATA)> <!ELEMENT SourceSystem (#PCDATA)>
and here's the xml that I want to validate:
<!DOCTYPE PDList SYSTEM "http://ifmp.nasa.gov/PDList.dtd"> <PDList RunDateTime="200203211000"> <PD PDNumber="10449"> <PayPlan>Text</PayPlan> <Grade>Text</Grade> <OccupationalSeries>Text</OccupationalSeries> <NASAPositionTitle>Text</NASAPositionTitle> <OPMPositionTitle>Text</OPMPositionTitle> <FileName>Text</FileName> <NASALocation>Text</NASALocation> <DutyLocation>Text</DutyLocation> <OrganizationalCode>Text</OrganizationalCode> <NASAClassCode>Text</NASAClassCode> <SourceSystem>Avue version whatever</SourceSystem> </PD> <PD PDNumber="1306x"> <PayPlan>Text</PayPlan> <Grade>Text</Grade> <OccupationalSeries>Text</OccupationalSeries> <NASAPositionTitle>Text</NASAPositionTitle> <OPMPositionTitle>Text</OPMPositionTitle> <FileName>Text</FileName> <NASALocation>Text</NASALocation> <DutyLocation>Text</DutyLocation> <OrganizationalCode>Text</OrganizationalCode> <NASAClassCode>Text</NASAClassCode> <SourceSystem>Avue version whatever</SourceSystem> </PD> <PD PDNumber="1307x"> <PayPlan>Text</PayPlan> <Grade>Text</Grade> <OccupationalSeries>Text</OccupationalSeries> <NASAPositionTitle>Text</NASAPositionTitle> <OPMPositionTitle>Text</OPMPositionTitle> <FileName>Text</FileName> <NASALocation>Text</NASALocation> <DutyLocation>Text</DutyLocation> <OrganizationalCode>Text</OrganizationalCode> <NASAClassCode>Text</NASAClassCode> <SourceSystem>Avue version whatever</SourceSystem> </PD> </PDList>
Any help or a really easy example script would be a big help. Thanks friends! I like chicken.

In reply to XML Validation by Stegalex

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.