title: how to validate xml against dtd
body: <p>I have a XML document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE ONIXMessage SYSTEM "http://www.editeur.org/onix/2.1/reference/onix-international.dtd"&gt;
  &lt;ONIXMessage&gt;
    &lt;Header&gt;
      &lt;FromCompany&gt;Companyy&lt;/FromCompany&gt;
      &lt;SentDate&gt;20101213&lt;/SentDate&gt;
    &lt;/Header&gt;
    &lt;Product&gt;
      &lt;RecordReference&gt;153640&lt;/RecordReference&gt;
      &lt;NotificationType&gt;03&lt;/NotificationType&gt;
      &lt;ProductIdentifier&gt;
        &lt;ProductIDType&gt;03&lt;/ProductIDType&gt;
        &lt;IDValue&gt;9785714009341&lt;/IDValue&gt;
      &lt;/ProductIdentifier&gt;
      &lt;ProductForm&gt;AC&lt;/ProductForm&gt;
      &lt;NumberOfPieces&gt;1&lt;/NumberOfPieces&gt;
      &lt;ProductClassification&gt;
          &lt;ProductClassificationType&gt;02&lt;/ProductClassificationType&gt;
          &lt;ProductClassificationCode&gt;55101514&lt;/ProductClassificationCode&gt;
      &lt;/ProductClassification&gt;
      &lt;Title&gt;
        &lt;TitleType&gt;01&lt;/TitleType&gt;
        &lt;TitleText&gt;Jazz Piano. Volume 3.&lt;/TitleText&gt;
      &lt;/Title&gt;
      &lt;Contributor&gt;
        &lt;SequenceNumber&gt;1&lt;/SequenceNumber&gt;
        &lt;ContributorRole&gt;A01&lt;/ContributorRole&gt;
        &lt;PersonName&gt;Waller Fats&lt;/PersonName&gt;
        &lt;PersonNameInverted&gt;Fats, Waller&lt;/PersonNameInverted&gt;
        &lt;TitlesBeforeNames&gt; &lt;/TitlesBeforeNames&gt;
        &lt;NamesBeforeKey&gt;Waller&lt;/NamesBeforeKey&gt;
        &lt;PrefixToKey&gt; &lt;/PrefixToKey&gt;
        &lt;KeyNames&gt;Fats&lt;/KeyNames&gt;
        &lt;SuffixToKey&gt; &lt;/SuffixToKey&gt;
      &lt;/Contributor&gt;
      &lt;Contributor&gt;
        &lt;SequenceNumber&gt;2&lt;/SequenceNumber&gt;
        &lt;ContributorRole&gt;A01&lt;/ContributorRole&gt;
        &lt;PersonName&gt;Peterson Oscar&lt;/PersonName&gt;
        &lt;PersonNameInverted&gt;Oscar, Peterson&lt;/PersonNameInverted&gt;
        &lt;TitlesBeforeNames&gt; &lt;/TitlesBeforeNames&gt;
        &lt;NamesBeforeKey&gt;Peterson&lt;/NamesBeforeKey&gt;
        &lt;PrefixToKey&gt; &lt;/PrefixToKey&gt;
        &lt;KeyNames&gt;Oscar&lt;/KeyNames&gt;
        &lt;SuffixToKey&gt; &lt;/SuffixToKey&gt;
      &lt;/Contributor&gt;
      &lt;Contributor&gt;
        &lt;SequenceNumber&gt;3&lt;/SequenceNumber&gt;
        &lt;ContributorRole&gt;A01&lt;/ContributorRole&gt;
        &lt;PersonName&gt;Kenton Stan&lt;/PersonName&gt;
        &lt;PersonNameInverted&gt;Stan, Kenton&lt;/PersonNameInverted&gt;
        &lt;TitlesBeforeNames&gt; &lt;/TitlesBeforeNames&gt;
        &lt;NamesBeforeKey&gt;Kenton&lt;/NamesBeforeKey&gt;
        &lt;PrefixToKey&gt; &lt;/PrefixToKey&gt;
        &lt;KeyNames&gt;Stan&lt;/KeyNames&gt;
        &lt;SuffixToKey&gt; &lt;/SuffixToKey&gt;
      &lt;/Contributor&gt;
      &lt;Contributor&gt;
        &lt;SequenceNumber&gt;4&lt;/SequenceNumber&gt;
        &lt;ContributorRole&gt;A01&lt;/ContributorRole&gt;
        &lt;PersonName&gt;Evans Bill&lt;/PersonName&gt;
        &lt;PersonNameInverted&gt;Bill, Evans&lt;/PersonNameInverted&gt;
        &lt;TitlesBeforeNames&gt; &lt;/TitlesBeforeNames&gt;
        &lt;NamesBeforeKey&gt;Evans&lt;/NamesBeforeKey&gt;
        &lt;PrefixToKey&gt; &lt;/PrefixToKey&gt;
        &lt;KeyNames&gt;Bill&lt;/KeyNames&gt;
        &lt;SuffixToKey&gt; &lt;/SuffixToKey&gt;
      &lt;/Contributor&gt;
      &lt;Contributor&gt;
        &lt;SequenceNumber&gt;5&lt;/SequenceNumber&gt;
        &lt;ContributorRole&gt;A01&lt;/ContributorRole&gt;
        &lt;PersonName&gt;Shearing George&lt;/PersonName&gt;
        &lt;PersonNameInverted&gt;George, Shearing&lt;/PersonNameInverted&gt;
        &lt;TitlesBeforeNames&gt; &lt;/TitlesBeforeNames&gt;
        &lt;NamesBeforeKey&gt;Shearing&lt;/NamesBeforeKey&gt;
        &lt;PrefixToKey&gt; &lt;/PrefixToKey&gt;
        &lt;KeyNames&gt;George&lt;/KeyNames&gt;
        &lt;SuffixToKey&gt; &lt;/SuffixToKey&gt;
      &lt;/Contributor&gt;
      &lt;Contributor&gt;
        &lt;SequenceNumber&gt;6&lt;/SequenceNumber&gt;
        &lt;ContributorRole&gt;A01&lt;/ContributorRole&gt;
        &lt;PersonName&gt;D. Ellington&lt;/PersonName&gt;
        &lt;PersonNameInverted&gt;Ellington, D.&lt;/PersonNameInverted&gt;
        &lt;TitlesBeforeNames&gt; &lt;/TitlesBeforeNames&gt;
        &lt;NamesBeforeKey&gt;D.&lt;/NamesBeforeKey&gt;
        &lt;PrefixToKey&gt; &lt;/PrefixToKey&gt;
        &lt;KeyNames&gt;Ellington&lt;/KeyNames&gt;
        &lt;SuffixToKey&gt; &lt;/SuffixToKey&gt;
      &lt;/Contributor&gt;
      &lt;Contributor&gt;
        &lt;SequenceNumber&gt;7&lt;/SequenceNumber&gt;
        &lt;ContributorRole&gt;A01&lt;/ContributorRole&gt;
        &lt;PersonName&gt;Corea Chic&lt;/PersonName&gt;
        &lt;PersonNameInverted&gt;Chic, Corea&lt;/PersonNameInverted&gt;
        &lt;TitlesBeforeNames&gt; &lt;/TitlesBeforeNames&gt;
        &lt;NamesBeforeKey&gt;Corea&lt;/NamesBeforeKey&gt;
        &lt;PrefixToKey&gt; &lt;/PrefixToKey&gt;
        &lt;KeyNames&gt;Chic&lt;/KeyNames&gt;
        &lt;SuffixToKey&gt; &lt;/SuffixToKey&gt;
      &lt;/Contributor&gt;
      &lt;Language&gt;
        &lt;LanguageRole&gt;01&lt;/LanguageRole&gt;
        &lt;LanguageCode&gt;rus&lt;/LanguageCode&gt;
      &lt;/Language&gt;
      &lt;NumberOfPages&gt;0&lt;/NumberOfPages&gt;
      &lt;MainSubject&gt;
        &lt;MainSubjectSchemeIdentifier&gt;20&lt;/MainSubjectSchemeIdentifier&gt;
        &lt;SubjectHeadingText&gt;Nuotit, Jazz pianolle&lt;/SubjectHeadingText&gt;
      &lt;/MainSubject&gt;
      &lt;OtherText&gt;
        &lt;TextTypeCode&gt;01&lt;/TextTypeCode&gt;
        &lt;Text&gt;Contents&amp;lt;br&amp;gt; 
  Thomas «Fats» WALLER. Keepin' out of Mischief Now
  Oscar PETERSON. Whisper Not
  Stan KENTON. Painted Rhythm
  Oscar PETERSON. The Nearness of You
  Stan KENTON. Southern Scandal&amp;lt;br&amp;gt; Nat «King» COLE. Blues&amp;lt;br&amp;gt; Bill EVANS. Interplay (Blues F minor)
  Bill EVANS. Very Early
  George SHEARING. Changing with the Times
  Duke ELLINGTON. Echoes of Harlem
  Chick COREA. Gemini&lt;/Text&gt;
      &lt;/OtherText&gt;
      &lt;MediaFile&gt;
        &lt;MediaFileTypeCode&gt;04&lt;/MediaFileTypeCode&gt;
        &lt;MediaFileFormatCode&gt;03&lt;/MediaFileFormatCode&gt;
        &lt;MediaFileLinkTypeCode&gt;01&lt;/MediaFileLinkTypeCode&gt;
        &lt;MediaFileLink&gt;9785714009341.jpg&lt;/MediaFileLink&gt;
        &lt;MediaFileDate&gt;20101220&lt;/MediaFileDate&gt;
      &lt;/MediaFile&gt; 
      &lt;ProductWebsite&gt;
        &lt;ProductWebsiteLink&gt;http://www.site.com/344.html&lt;/ProductWebsiteLink&gt;
      &lt;/ProductWebsite&gt;
      &lt;Publisher&gt;
        &lt;PublisherName&gt;Muzyka&lt;/PublisherName&gt;
      &lt;/Publisher&gt;
      &lt;CountryOfPublication&gt;RU&lt;/CountryOfPublication&gt;
      &lt;PublishingStatus&gt;04&lt;/PublishingStatus&gt;
      &lt;PublicationDate&gt;2010&lt;/PublicationDate&gt;
      &lt;SupplyDetail&gt;
        &lt;SupplierName&gt;Company&lt;/SupplierName&gt;
        &lt;ProductAvailability&gt;21&lt;/ProductAvailability&gt;
        &lt;Price&gt;
          &lt;PriceTypeCode&gt;02&lt;/PriceTypeCode&gt;
          &lt;PriceAmount&gt;9.0000&lt;/PriceAmount&gt;
          &lt;CurrencyCode&gt;EUR&lt;/CurrencyCode&gt;
          &lt;TaxRateCode1&gt;S&lt;/TaxRateCode1&gt;
          &lt;TaxRatePercent1&gt;9&lt;/TaxRatePercent1&gt;
        &lt;/Price&gt;
      &lt;/SupplyDetail&gt;
    &lt;/Product&gt;
  &lt;/ONIXMessage&gt;
  </code></pre>
  
  <p>Validation code is:</p>
  
  <pre><code>    xml = "this XML document above";
  
      var r = new XmlTextReader(new StringReader(xml));
      var settings = new XmlReaderSettings();
      var sb = new StringBuilder();
  
      settings.ProhibitDtd = false;
      settings.ValidationType = ValidationType.DTD;
      settings.ValidationEventHandler += (a, e) =&gt;
                                         {
                                             sb.AppendLine(e.Message);
                                             ret = false;
                                         };
  
      XmlReader validator = XmlReader.Create(r, settings);
  
      while (validator.Read())
      {
      }
      validator.Close();
  </code></pre>
  
  <p>I got validation error:</p>
  
  <blockquote>
    <p>The element 'Product' has invalid
    child element 'Language'. List of
    possible elements expected:
    'Contributor NumberWithinSeries
    YearOfAnnual ISBNOfSet EAN13OfSet
    ProductIdentifier TitleOfSet Title Set
    TextCaseFlag DistinctiveTitle
    TitlePrefix Title'.</p>
  </blockquote>
  
  <p>But when I send this XML to my partner, he says that document contains no validation errors.
  They use org.dom4j.io.SAXReader to validate it.
  How can it be possible? Do I do valiation right? </p>