?
Solved

XMLValidatingReader is Obsolete

Posted on 2006-11-10
2
Medium Priority
?
1,249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
VovinE earned 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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 introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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