Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. How to get behavior similar to the obsoleted XmlValidatingReader

How to get behavior similar to the obsoleted XmlValidatingReader

Scheduled Pinned Locked Moved XML / XSL
xmlhelpquestiondatabasetutorial
4 Posts 2 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Whitmire
    wrote on last edited by
    #1

    Finally tired of the "System.Xml.XmlValidatingReader is obsolete" message, I undertook to replace it with the recommended XmlReader. The obsolescence documentation from MS wasn't much help, but I did manage to create code that compiled, as follows:

    string nameSpace = GetSchemaNamespace(_XmlDocumentStream);
    XmlTextReader schemaReader = new XmlTextReader(_SchemaStream);
    XmlSchemaSet xsc = new XmlSchemaSet();
    xsc.Add(nameSpace, schemaReader);
    XmlNameTable nt = new NameTable();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
    XmlParserContext parserContext = new XmlParserContext(nt, nsmgr, null, XmlSpace.None);
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ValidationType = ValidationType.Schema;
    settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
    settings.Schemas.Add(xsc);
    settings.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);
    XmlReader reader = XmlReader.Create(_XmlDocumentStream, settings, parserContext);

    And then I found these two things I don't understand: 1.  First, the Create failed because this attribute in the xsd wasn't defined.

    There was no complaint over this from the obsolete class. From the error message, I assume that this line previously covered that definition:

    What changed such that this is now a fatal error? 2.  I removed the references to the above attribute so I could get a reader created and ran our set of unit tests for this process. The next surprise was that the reader doesn't handle validation errors the same as before. (a) Undefined attributes used to be Warnings. Now they are Errors. So what is now considered a warning? (b) It used to continue on from errors, allowing us to compile a list of errors and warnings for the XML being validated. Now, it bails out after the first error and I never get more than one invocation of the ValidationEventHandler. The test case that used to yield 43 errors and 21 warnings now produces a single error (and the test therefore fails). Is there a way to get the former behavior back?

    L J 2 Replies Last reply
    0
    • J John Whitmire

      Finally tired of the "System.Xml.XmlValidatingReader is obsolete" message, I undertook to replace it with the recommended XmlReader. The obsolescence documentation from MS wasn't much help, but I did manage to create code that compiled, as follows:

      string nameSpace = GetSchemaNamespace(_XmlDocumentStream);
      XmlTextReader schemaReader = new XmlTextReader(_SchemaStream);
      XmlSchemaSet xsc = new XmlSchemaSet();
      xsc.Add(nameSpace, schemaReader);
      XmlNameTable nt = new NameTable();
      XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
      XmlParserContext parserContext = new XmlParserContext(nt, nsmgr, null, XmlSpace.None);
      XmlReaderSettings settings = new XmlReaderSettings();
      settings.ValidationType = ValidationType.Schema;
      settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
      settings.Schemas.Add(xsc);
      settings.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);
      XmlReader reader = XmlReader.Create(_XmlDocumentStream, settings, parserContext);

      And then I found these two things I don't understand: 1.  First, the Create failed because this attribute in the xsd wasn't defined.

      There was no complaint over this from the obsolete class. From the error message, I assume that this line previously covered that definition:

      What changed such that this is now a fatal error? 2.  I removed the references to the above attribute so I could get a reader created and ran our set of unit tests for this process. The next surprise was that the reader doesn't handle validation errors the same as before. (a) Undefined attributes used to be Warnings. Now they are Errors. So what is now considered a warning? (b) It used to continue on from errors, allowing us to compile a list of errors and warnings for the XML being validated. Now, it bails out after the first error and I never get more than one invocation of the ValidationEventHandler. The test case that used to yield 43 errors and 21 warnings now produces a single error (and the test therefore fails). Is there a way to get the former behavior back?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2
      1. Try adding handlers directly to the reader and see if you get any further; e.g.

      XmlSerializer serializer = new XmlSerializer( typeof( ... ) );

      serializer.UnknownNode += new XmlNodeEventHandler( serializer_UnknownNode );
      serializer.UnknownAttribute += new XmlAttributeEventHandler( serializer_UnknownAttribute );

      J 1 Reply Last reply
      0
      • L Lost User
        1. Try adding handlers directly to the reader and see if you get any further; e.g.

        XmlSerializer serializer = new XmlSerializer( typeof( ... ) );

        serializer.UnknownNode += new XmlNodeEventHandler( serializer_UnknownNode );
        serializer.UnknownAttribute += new XmlAttributeEventHandler( serializer_UnknownAttribute );

        J Offline
        J Offline
        John Whitmire
        wrote on last edited by
        #3

        I don't see a way to use that suggestion with the parts that I have. The errors of interest are not going to be found by the default serializer; they are schema conformance errors, relating to a specific xsd, and not plain XML errors.

        1 Reply Last reply
        0
        • J John Whitmire

          Finally tired of the "System.Xml.XmlValidatingReader is obsolete" message, I undertook to replace it with the recommended XmlReader. The obsolescence documentation from MS wasn't much help, but I did manage to create code that compiled, as follows:

          string nameSpace = GetSchemaNamespace(_XmlDocumentStream);
          XmlTextReader schemaReader = new XmlTextReader(_SchemaStream);
          XmlSchemaSet xsc = new XmlSchemaSet();
          xsc.Add(nameSpace, schemaReader);
          XmlNameTable nt = new NameTable();
          XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
          XmlParserContext parserContext = new XmlParserContext(nt, nsmgr, null, XmlSpace.None);
          XmlReaderSettings settings = new XmlReaderSettings();
          settings.ValidationType = ValidationType.Schema;
          settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
          settings.Schemas.Add(xsc);
          settings.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);
          XmlReader reader = XmlReader.Create(_XmlDocumentStream, settings, parserContext);

          And then I found these two things I don't understand: 1.  First, the Create failed because this attribute in the xsd wasn't defined.

          There was no complaint over this from the obsolete class. From the error message, I assume that this line previously covered that definition:

          What changed such that this is now a fatal error? 2.  I removed the references to the above attribute so I could get a reader created and ran our set of unit tests for this process. The next surprise was that the reader doesn't handle validation errors the same as before. (a) Undefined attributes used to be Warnings. Now they are Errors. So what is now considered a warning? (b) It used to continue on from errors, allowing us to compile a list of errors and warnings for the XML being validated. Now, it bails out after the first error and I never get more than one invocation of the ValidationEventHandler. The test case that used to yield 43 errors and 21 warnings now produces a single error (and the test therefore fails). Is there a way to get the former behavior back?

          J Offline
          J Offline
          John Whitmire
          wrote on last edited by
          #4

          Hey, Moderator, I now think this would be more appropriate for the XML forum. Do you agree?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups