I've tried this for a while, and am having trouble writing an XML start element in C# with XmlWriter.
The output line is supposed to look like: <s:Scenario xmlns:s="./scenarios" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
But the best I've been able to get has been: <s:Scenario xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="./scenarios" />
with the following code:
xmlWriter.WriteStartElement("s", "Scenario", "./scenarios");
xmlWriter.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
Is there a better way to write this line? WriteRaw will not work, because this is supposed to be the first line following xmlWriter.WriteStartDocument();
, and it ends up throwing an InvalidOperationException: "Token StartElement in state EndRootElement would result in an invalid XML document. (...)."
Let me know if you need more context! Thanks in advance.