XML data file not opening and working properly

ronmouse

New Member
I developed a WPF application using XML as the database file. Yesterday, the program stopped working. After some checking, I saw that there was a problem with Transaction.xml file. I tried opening the same in IE, but got this error\[quote\] The XML page cannot be displayed Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later. An invalid character was found in text content. Error processing resource 'file:///C:/RegisterMaintenance/Transaction.xml\[/quote\]Then, I tried opening the file in notepad and it showed weird character(screenshot below).
ps8DJ.jpg
In the end, its displaying the right structure of xml. Please tell me what has gone wrong and why the xml not showing correctly. How can get it to normal state. I am really worried as this is my only data file. Any help or suggestion will be great.One of the codes that edit this file, there are other similar types of code files that use Transaction.xml\[code\]public string Add() { XDocument doc1 = XDocument.Load(@"Ledgers.xml"); XElement elem = (from r in doc1.Descendants("Ledger") where r.Element("Name").Value =http://stackoverflow.com/questions/11447156/= 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"; }\[/code\]
 
Back
Top