Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validating xml stream against xsd file

Status
Not open for further replies.

jrenae

Programmer
Jan 18, 2006
142
US
I'm trying to validate my stream of xml via an XMLReader, but it is saying it can't find the elements when they're clearly in the xsd file.

When it gets to the part While Xrdr.Read(), it goes into the validation event and gives me the error. It's like it's not recognizing the schema. Am I missing a setting?
Thanks much.
error:
Could not find schema information for the element 'Ping'.


partial xsd file:
<xs:element name="Ping" type="xs:boolean" />


Code:
        public XmlSchema GetSchema()
        {



            XmlSchemaSet schemaSet = new XmlSchemaSet();
            schemaSet.Add("[URL unfurl="true"]http://tempuri.org/DetailsSchema1.xsd",[/URL] "C:/Projects/ReplyEnterpriseBusiness/ReplyEnterpriseBUS/DetailsSchema1.xsd");
            schemaSet.Compile();
            XmlSchema detailsSchema = null;
            foreach (XmlSchema schema in schemaSet.Schemas())
            {
                detailsSchema = schema;
            }

            return detailsSchema;

         }

        public Boolean ValidateXML(MemoryStream mstr)
        {

            XmlReaderSettings xRdrSettings = new XmlReaderSettings();
            XmlSchema xSchema = GetSchema();
           
            xRdrSettings.Schemas.Add(xSchema);

            xRdrSettings.ValidationType = ValidationType.Schema;
            xRdrSettings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
            
            

            xRdrSettings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
            
            mstr.Position = 0;
            XmlReader xRdr = XmlReader.Create(mstr, xRdrSettings);
            while (xRdr.Read()) ;

            return true;
        
        }

        private static void ValidationCallBack(object sender, ValidationEventArgs e)
        {
            string message = "";

            message = e.Message;

            //return message;
        }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top