我正在研究一个概念EFile
我按照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");
}
答案 0 :(得分:1)
导致错误的是导致XSD
导致错误的导致XML
导致错误XML
只需更改<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"
>
,如下所示
{{1}}
这样可行......
答案 1 :(得分:0)
将xsi:NamespaceSchemaLocation
更改为xsi:noNamespaceSchemaLocation
。还可以尝试将其设为URL,如下所示:xsi:noNamespaceSchemaLocation="file:///D:/foldername/XML/XMLValidate/ReturnData941.xsd