2011-12-24 167 views
2

我一個概念工作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

任何人都可以告訴我哪裏出錯了。 – Chaitanya 2011-12-26 07:51:52

回答

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

謝謝很多'Dorababu'你剛剛救了我的生命..這對我來說很完美 – Chaitanya 2011-12-26 11:57:44

+0

歡迎光臨'Chaitanya' – Dotnet 2011-12-26 11:59:39

+0

澄清問題中的xml無法指定根元素ReturnData的命名空間,它既沒有定義默認命名空間,也就是xmlns =「...」在此答案中已更正,它也沒有指定命名空間前綴到元素名稱,即rd:ReturnData xmlns:rd =「...」 – 2018-02-21 00:19:39

0

更改xsi:NamespaceSchemaLocationxsi:noNamespaceSchemaLocation。也可以嘗試使其成爲一個URL,就像這樣:xsi:noNamespaceSchemaLocation="file:///D:/foldername/XML/XMLValidate/ReturnData941.xsd

+0

即使同樣的錯誤 – Chaitanya 2011-12-24 10:25:10

+0

請參閱修改後的答案以獲取其他內容。 – 2011-12-24 10:28:31

+0

仍然是同一個問題:( – Chaitanya 2011-12-24 10:34:51