validating XML against my XSD is not working

Dear all

i am wroking with VS2010, C#, Web Services

i have an XSD file and XML file.
i want to validate the XML against the XSD.

i tried a lot of trials and it is not working.

here is my code:
internal static bool ValidXmlDoc(string xml)
        {
            if (xml == "")
            {
                return false;
            }

            bool isValidXml = true;
            XmlValidatingReader vr;
            XmlTextReader tr;
            XmlSchemaCollection schemaCol = new XmlSchemaCollection();

            schemaCol.Add("http://www.f-eg.com/ebpp/IFXMessages/", ConfigurationManager.AppSettings["MyXSD"].ToString());
         
            try
            {
                StringReader srXML = new StringReader(xml);
                // Read the xml.
                tr = new XmlTextReader(srXML);

                // Create the validator.
                vr = new XmlValidatingReader(tr);

                // Set the validation type.
                vr.ValidationType = ValidationType.Schema;

                // Add the schema.
                if (schemaCol != null)
                {
                    vr.Schemas.Add(schemaCol);
                }

                // Read the xml schema.
                while (vr.Read())
                {
                    /*
                     * There is no code here
                     * It automatically checks the given request with the schema
                     */
                }

                vr.Close();

                return isValidXml;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                // Clean up...
                vr = null;
                tr = null;
            }
        }

Open in new window


attach is the Schema New.xsd.

thanks,
RamzyNEbeidAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy PooleCommented:
can you also attach an xml file you are trying to validate.
0
Geert BormansInformation ArchitectCommented:
The schema is not complete
You are only declaring two complexTypes, you need to declare at least one global element that you can use as the root of your document.
Inside the complex type definitions you are referenceing other types that are not declared in a global fashin in your schema.
This schema is not complete, you likely missed some imports of other schema components.
As Randy says, a copy of the source XML would help.
But at least you know the schema is not complete
0
Randy PooleCommented:
BTW, you can validate your schema, and xml vs your schema here:
http://www.utilities-online.info/xsdvalidation/#.VAWzjz_4WCc
0
Geert BormansInformation ArchitectCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.