I am building an xml file. Parts of the file are static. Some of the file is dynamic. My code has an error of “Null object reference”.
Any tips would be awesome.
private XElement BuildDataElement()
{
// this is going to be more complicated
return new XElement("data");
}
public void TestXML(string fname)
{
// build the data element
XElement allData = BuildDataElement();
// Build the header
XDocument doc = new XDocument(
new XElement("map",
new XAttribute("showLabels", "1"),
new XAttribute("includeNameInLabels", "1"),
new XElement("colorRange",
new XElement("color",
new XAttribute("minValue", "1")
)
),
allData,
new XElement("application",
new XElement("apply",
new XAttribute("toObject", "TOOLTIP"),
new XAttribute("styles", "TTipFont,MyDataPlotStyle")
)
)
)
);
if (File.Exists(fname))
File.Delete(fname);
doc.Save(fname);
}