Reputation: 379
I am working on a concept EFile
I wrote the sample structure as per specified in the PDF's
but i am unable to validate the XML
data i am getting the following errors when i execute that XML
file.
Could not find schema information for the element 'ReturnData'.Validation event
Could not find schema information for the attribute 'documentCount'.Validation event
Could not find schema information for the attribute 'http://www.w3.org/2001/XMLSchema-Instance:NamespaceSchemaLocation'.Validation event
Could not find schema information for the element 'ContentLocation'.Document is invalid
Can any one help me on this in-order to resolve my issues.
The sample XML
is as follows
<?xml version="1.0" encoding="UTF-8"?>
<ReturnData documentCount=""
xsi:NamespaceSchemaLocation="D:\foldername\XML\XMLValidate\ReturnData941.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance">
<ContentLocation />
</ReturnData>
This is my code
public void MyValidationEventHandler(object sender,
ValidationEventArgs args)
{
isValid = false;
Response.Write("Validation event<br/>" + args.Message);
}
protected void Button1_Click(object sender, EventArgs e)
{
string strPath1 = Server.MapPath("test.xml");
XmlTextReader r = new XmlTextReader(strPath1);
XmlValidatingReader v = new XmlValidatingReader(r);
v.ValidationType = ValidationType.Schema;
v.ValidationEventHandler +=
new ValidationEventHandler(MyValidationEventHandler);
while (v.Read())
{
// Can add code here to process the content.
}
v.Close();
// Check whether the document is valid or invalid.
if (isValid)
{
Response.Write("Document is valid");
//Response.Redirect("Product.xml");
}
else
Response.Write("Document is invalid");
}
Upvotes: 2
Views: 3324
Reputation: 8636
It's not the code that went wrong it is the import of XSD
that you made wrong in XML
just change your XML
as follows
<ReturnData documentCount=""
xmlns="http://www.irs.gov/efile"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.irs.gov/efile ReturnData941.xsd"
>
This will works fine...
Upvotes: 1
Reputation: 19443
Change the xsi:NamespaceSchemaLocation
to be xsi:noNamespaceSchemaLocation
. Also try making it a URL, like this: xsi:noNamespaceSchemaLocation="file:///D:/foldername/XML/XMLValidate/ReturnData941.xsd
Upvotes: 0