Solved

XMLValidatingReader is Obsolete

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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