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!

XML validating Reader: Cannot find schema information for the element

Status
Not open for further replies.

narreddi

Programmer
Jun 8, 2005
1
US
Here is a sample XML and xsd.

trial.xsd as:

<?xml version="1.0" ?>
<xs:schema xmlns:xs=" xmlns="urn:BTC-schema" targetNamespace="urn:BTC-schema" elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:element name="MMRequest" type="xs:string"/>
</xs:schema>


Sample XML as:

<?xml version="1.0" encoding="UTF-8" ?>
<MMRequest xmlns:xs='urn:BTC-schema' xmlns:xsi='Please Work</MMRequest>

Here is the code that uses a XML validator:

public bool ValidateInput(string inxml)
{

try
{
Success=true;
inxml="<MMRequest xmlns:xs='urn:BTC-schema'xmlns:xsi=' Work</MMRequest>";
//Create XML Parser Context
XmlParserContext context=new XmlParserContext(null, null, "", XmlSpace.None);
XmlSchemaCollection myschema = new XmlSchemaCollection();
myschema.Add("urn:BTC-schema","c:\\DTD\\btc\\trial.xsd");
XmlValidatingReader valreader=new XmlValidatingReader(inxml,XmlNodeType.Element,context);
valreader.ValidationType= System.Xml.ValidationType.Schema;
valreader.ValidationEventHandler +=new System.Xml.Schema.ValidationEventHandler(OnValidationError);
while(valreader.Read())
{
string k=valreader.Name.ToString();
}
valreader.Close();
return this.Success;
}
catch(Exception ex)
{
Log.LogToFile("Error generated in ValidateInput with Details:"+ex.ToString());
return false;
}
}
private void OnValidationError(object sender, ValidationEventArgs e)
{
this.Success=false;
//Console.WriteLine(e.Message);

}


When i try to validate, I keep getting an error:
Cannot find schema information for element MMRequest. Anyideas???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top