Hello everyone I want to check my xml file if it is empty or not. I am trying to update one xml data to another for this I am using the following code.Now Please tell me how can I check if my xml file has data or not Here is the code I am using for 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)
{
//Catch xml exception
//in your case: root element is missing
}
}
I am Getting this error
Data at the root level is invalid. Line 1, position 1.
Please tell me how can I check if my Updatelist.xml
is empty or not?
Now I get this error