This documentation is archived and is not being maintained.

Building an OASIS-Conformant Reader

.NET Framework 1.1

The Organization for the Advancement of Structured Information Standards, OASIS, provides conformance tests based on public standards for Standard Generalized Markup Language (SGML), Extensible Markup Language (XML), and other structured information processing. For more information about OASIS conformance tests and the OASIS mission and charter, see http://www.oasis-open.org.

To build a conformant reader that is capable of testing the OASIS conformance test suites, all default settings for XmlTextReader and XmlValidatingReader are required, with the following exceptions:

  • In the XmlTextReader, set Normalization to true (the default is false).
  • In the XmlValidatingReader, assign a ValidationCallback handler (by default the reader throws exceptions).
  • Set the XmlValidatingReader to ValidationType.DTD (the default is Auto).

The following example shows an OASIS-conformant reader that takes an XML file as input.

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema

Class ConformantReader
   
   Private Sub ValidationCallback(sender As Object, args As ValidationEventArgs)
      Console.WriteLine("++++++++++++++ ValidationCallback ++++++++++++++")
      Console.WriteLine("Error Message: {0}", args.Message)
      Console.WriteLine("Severity: {0}", args.Severity)
   End Sub 'ValidationCallback
   
   
   Public Sub TraceFile(app_args() As String)
      Dim vrdr As XmlValidatingReader = Nothing
      Dim rdr As XmlTextReader = Nothing
      Dim InputFile As String = app_args(0)
      
      Try
         rdr = New XmlTextReader(InputFile)
         'Default XmlTextReader settings.
         rdr.WhitespaceHandling = WhitespaceHandling.All
         rdr.Namespaces = true
         rdr.Normalization = True
         vrdr = New XmlValidatingReader(rdr)
         'Default XmlValidatingReader settings.
          vrdr.EntityHandling = EntityHandling.ExpandEntities
          vrdr.ValidationType = ValidationType.DTD
          AddHandler vrdr.ValidationEventHandler, AddressOf ValidationCallBack
         
         While vrdr.Read()
            If vrdr.NodeType = XmlNodeType.EntityReference Then
               vrdr.ResolveEntity()
            End If
         End While
         
         Console.WriteLine("Reading of {0} completed.", InputFile)
      Catch e As XmlException
         If Not (vrdr Is Nothing) Then
            vrdr.Close()
         End If
         If Not (rdr Is Nothing) Then
            rdr.Close()
         End If
         Console.WriteLine("++++++++++++++ Exception ++++++++++++++")
         Console.WriteLine(e.ToString())
      End Try
   End Sub 'TraceFile
   
   Public Shared Function Main(args() As String) As Integer
      Dim RunRdr As New ConformantReader()
      RunRdr.TraceFile(args)
      Return 0
   End Function 'Main
End Class 'ConformantReader
[C#]
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

class ConformantReader {
    private void ValidationCallback(object sender, ValidationEventArgs args ) {
        Console.WriteLine("++++++++++++++ ValidationCallback ++++++++++++++");
        Console.WriteLine("Error\tMessage:\t{0}",args.Message);
        Console.WriteLine("\tSeverity:\t{0}",args.Severity);
    }

    public void TraceFile(string[] app_args) {
        XmlValidatingReader vrdr = null;
        XmlTextReader rdr = null;
        string InputFile = app_args[0];

        try {
            rdr = new XmlTextReader(InputFile);
            /* Default XmlTextReader settings.
            rdr.WhitespaceHandling = WhitespaceSetting.All;
            rdr.Namespaces = true;
            */
            rdr.Normalization = true;

            vrdr = new XmlValidatingReader(rdr);
            /* Default XmlValidatingReader settings.
            vrdr.EntityHandling = EntityHandling.ExpandEntities;
            */
            vrdr.ValidationType = ValidationType.DTD;
            vrdr.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallback);

            while (vrdr.Read()) {                        
                if (vrdr.NodeType == XmlNodeType.EntityReference) {
                    vrdr.ResolveEntity();
                }
            }

            Console.WriteLine("\nReading of {0} completed.",InputFile);
        }
        catch(XmlException e) {
            if ( vrdr != null ) vrdr.Close();
            if ( rdr != null) rdr.Close();
            Console.WriteLine("++++++++++++++ Exception ++++++++++++++");
            Console.WriteLine(e.ToString());
        }
    }

    public static int Main(string[] args) {
        ConformantReader RunRdr = new ConformantReader();
        RunRdr.TraceFile(args);
        return 0;
    } 
}

The following XML file is passed in with the preceding code example.

<!--XML file using a DTD-->
<!DOCTYPE bookstore [
  <!ELEMENT bookstore (cd)*> 
  <!ELEMENT cd (title,artist,price)>
  <!ATTLIST cd genre CDATA #REQUIRED>
  <!ELEMENT title (#PCDATA)>
  <!ELEMENT artist (#PCDATA)>
  <!ELEMENT price (#PCDATA)>]>
<bookstore>
  <cd genre="alternative">
    <title>Americana</title>
    <artist>Offspring</artist>
    <price>16.95</price>
  </cd>
</bookstore>

See Also

Validation of XML with Schemas | XDR Validation with XmlSchemaCollection | XML Schema (XSD) Validation with XmlSchemaCollection

Show: