Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

XMLValidatingReader is Obsolete

Posted on 2006-11-10
2
Medium Priority
?
1,285 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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