Solved

XMLValidatingReader is Obsolete

Posted on 2006-11-10
2
1,184 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 63
Remove greater than sign 3 50
Help with C#, MVC, razor. 6 23
Reference issues in Visual Studio 3 0
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

864 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

19 Experts available now in Live!

Get 1:1 Help Now