Try removing:
rootnode.AppendChild(rootnode);
The root node cannot be a child of itself.
Then add the following two lines:
doc.DocumentElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
doc.DocumentElement.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
Add this
after doc.AppendChild(rootnode);