Hi everyone, I want to check my xml file if it is empty or not. I am trying to update one XML data for another. I am using the following code. Now please tell me how can I check if there is data in my XML file or not? Here is the code I use to update my xml file
protected void CheckUpdates()
{
StringReader strReader = new StringReader("..\\xml\\Updatelist.xml");
XmlReader reader = XmlReader.Create(strReader);
try
{
while (reader.Read())
{
var originalXmlDoc = XDocument.Load("..\\xml\\list.xml"); var newXmlDoc = XDocument.Load("..\\xml\\Updatelist.xml");
foreach (var newElement in newXmlDoc.Element("blocker").Elements("lst"))
{
newElement.Value.Trim();
if (!originalXmlDoc.Element("blocker").Elements("lst")
.Any(oldElement => oldElement.Value.Trim().Equals(
newElement.Value.Trim(),
StringComparison.InvariantCultureIgnoreCase)))
{
originalXmlDoc.Element("blocker").Add(new XElement("lst", newElement.Value));
}
}
originalXmlDoc.Save("..\\xml\\list.xml", SaveOptions.None);
XmlDocument doc = new XmlDocument();
doc.Load("..\\xml\\Updatelist.xml");
doc.DocumentElement.RemoveAll();
doc.Save("..\\xml\\Updatelist.xml");
}
}
catch (XmlException ex)
{
}
}
I get this error
Data at the root level is invalid. Line 1, position 1.
Please tell me how can I check if mine is empty Updatelist.xmlor not?
Now i get this error
source
share