找不到该元素的架构信息

时间:2011-12-24 10:20:36

标签: asp.net xml xsd

我正在研究一个概念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");
}

2 个答案:

答案 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