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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

illegal Characters in Xml when sent to XMLreade

Status
Not open for further replies.

nicklieb

Programmer
Oct 17, 2002
383
GB
I am trying to create a listener page, that will validate and incoming XML document with an XSD.

Code:
StreamReader InboundStream = new StreamReader(Page.Request.InputStream);
string UseString = InboundStream.ReadToEnd();
InboundStream.Close();

string result = ValidateXML(xmlString);

    public string ValidateXML(string UseString)
    {
        try
        {
            XmlReader xmlrdr = XmlReader.Create(new StringReader(UseString));
            xmlrdr.Settings.ValidationType = ValidationType.Schema;
            xmlrdr.Settings.Schemas.Add(null, "Schemas\ttc1.xsd");
            xmlrdr.Settings.ValidationEventHandler += new ValidationEventHandler(ValidationHandler);
           
            while (xmlrdr.Read()) ;
            return "Validated";
        }
        catch (Exception ex)
        {
            return ex.Message + "<br>" + ErrorsCount + "<br>" + ErrorMessage;
        }          
    }

When it hits XMLReader.Create is bombs out with the illegal character, but gives no indication where it is.

Has anyone had experience of create a listener and validating against a schema? This is using .NET 2.0 which differs slightly from 1.1 where you have to setup the XMLValidator class. in 2.0 you can lump everything intogether.. ( or so i keep reading!!)

thanks in advance

 
If you are having a string 'UseString' and XmlReader.Create (String). Then use it directly as:
XmlReader xmlrdr = XmlReader.Create(UseString);

Sharing the best from my side...

--Prashant--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top