Solved

XMLValidatingReader is Obsolete

Posted on 2006-11-10
2
1,165 Views
Last Modified: 2012-05-05
I  am not that familiar with xml documents, as I compile this function I find that XmlValidatingReader is obsolete.  please help.


public static object XmlDeserialize(string xml, Type type, string xsd)
{
      ArgumentValidation.CheckString(xml, "xml");
      object obj1 = null;
      XmlReader reader1 = null;
      XmlTextReader reader2 = null;
      try
      {
            if ((xsd != null) && (xsd != string.Empty))
            {
                  reader2 = new XmlTextReader(new StringReader(xsd));
                  reader1 = new XmlValidatingReader(new XmlTextReader(new StringReader(xml)));
                  ((XmlValidatingReader) reader1).ValidationType = ValidationType.Schema;
                  XmlSchemaCollection collection1 = new XmlSchemaCollection();
                  collection1.Add(null, reader2);
                  ((XmlValidatingReader) reader1).Schemas.Add(collection1);
            }
            else
            {
                  reader1 = new XmlTextReader(new StringReader(xml));
            }
            obj1 = new XmlSerializer(type).Deserialize(reader1);
      }
      catch (Exception exception1)
      {
            string text1 = EventManager.LogEvent(EventLevel.Trace, "Serializer.XmlDeserialize", true, "XmlDeserializeFailure.2", new object[0]);
            throw new XmlDeserializationException(text1, exception1);
      }
      finally
      {
            if (reader2 != null)
            {
                  reader2.Close();
            }
            if (reader1 != null)
            {
                  reader1.Close();
            }
      }
      return obj1;
}

0
Comment
Question by:wenyonk
2 Comments
 
LVL 6

Accepted Solution

by:
VovinE earned 500 total points
ID: 17920840
just change this:
          if ((xsd != null) && (xsd != string.Empty))
            {
                  reader2 = new XmlTextReader(new StringReader(xsd));
                  reader1 = new XmlValidatingReader(new XmlTextReader(new StringReader(xml)));
                  ((XmlValidatingReader) reader1).ValidationType = ValidationType.Schema;
                  XmlSchemaCollection collection1 = new XmlSchemaCollection();
                  collection1.Add(null, reader2);
                  ((XmlValidatingReader) reader1).Schemas.Add(collection1);
            }



to this:

        if ((xsd != null) && (xsd != string.Empty))
        {
            reader2 = new XmlTextReader(new StringReader(xsd));

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.Schemas.Add(null,reader2);
            settings.ValidationType = ValidationType.Schema;

            reader1 = new XmlReader.Create(new StringReader(xml),settings);
        }

Mind that obsolete methods still work as they are suposed to, but indicate that it is advised not use them since they may change/disapear in the future.

hope it helps.
0
 

Author Comment

by:wenyonk
ID: 17925540
Thank you!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now