我寫的樣本結構按在PDF's
規定,但我無法驗證XML
數據我收到以下錯誤模式的信息時,我執行那個XML
文件。
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
任何人都可以幫助我解決我的問題。
樣品XML
是如下
<?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>
這是我的代碼
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");
}
任何人都可以告訴我哪裏出錯了。 – Chaitanya 2011-12-26 07:51:52