我開發了一個使用XML作爲數據庫文件的WPF應用程序。昨天,該計劃停止工作。經過一番檢查後,我看到Transaction.xml文件出現問題。我試圖在IE中打開相同,但得到這個錯誤XML數據文件沒有打開並正常工作
的XML頁面無法顯示
使用樣式表無法查看XML輸入。請更正錯誤,然後點擊刷新按鈕,或稍後再試。
在文本內容中發現無效字符。錯誤處理資源'file:/// C:/RegisterMaintenance/Transaction.xml
然後,我試圖打開記事本中的文件,它顯示了怪異的字符(屏幕截圖如下)。
在最後,其顯示XML的右側結構。請告訴我出了什麼問題,以及爲什麼xml無法正確顯示。如何才能達到正常狀態。我真的很擔心,因爲這是我唯一的數據文件。任何幫助或建議都會很棒。
一個是編輯該文件中的代碼,也有使用Transaction.xml
public string Add()
{
XDocument doc1 = XDocument.Load(@"Ledgers.xml");
XElement elem = (from r in doc1.Descendants("Ledger")
where r.Element("Name").Value == this.Buyer
select r).First();
this.TinNo = (string)elem.Element("TinNo");
this.PhoneNo = (string)elem.Element("PhoneNo");
this.CommissionAmount = (this.CommissionRate * this.Amount)/100;
this.CommissionAmount = Math.Round((decimal)this.CommissionAmount);
this.VatAmount = (this.CommissionAmount + this.Amount) * this.VatRate/100;
this.VatAmount = Math.Round((decimal)this.VatAmount);
this.InvoiceAmount = this.Amount + this.CommissionAmount + this.VatAmount;
XDocument doc2 = XDocument.Load(@"Transactions.xml");
var record = from r in doc2.Descendants("Transaction")
where (int)r.Element("Serial") == Serial
select r;
foreach (XElement r in record)
{
r.Element("Invoice").Add(new XElement("InvoiceNo", this.InvoiceNo), new XElement("InvoiceDate", this.InvoiceDate),
new XElement("TinNo", this.TinNo), new XElement("PhoneNo", this.PhoneNo), new XElement("TruckNo", this.TruckNo), new XElement("Source", this.Source),
new XElement("Destination", this.Destination), new XElement("InvoiceAmount", this.InvoiceAmount),
new XElement("CommissionRate", this.CommissionRate), new XElement("CommissionAmount", this.CommissionAmount),
new XElement("VatRate", this.VatRate), new XElement("VatAmount", this.VatAmount));
}
doc2.Save(@"Transactions.xml");
return "Invoice Created Successfully";
}
什麼是文件編碼? – 2012-07-12 07:51:18
它是'<?xml version =「1.0」encoding =「utf-8」?>' – 2012-07-12 07:55:45
是否有任何編輯器打開此文件,以便沒有奇怪的字符(可能是UltraEdit)? – 2012-07-12 08:17:29