I need to create an XmlDocument
with a root element containing multiple namespaces. Am using C# 2.0 or 3.0
Here is my code:
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("JOBS", "http://www.example.com");
doc.AppendChild(root);
XmlElement job = doc.CreateElement("JOB", "http://www.example.com");
root.AppendChild(job);
XmlElement docInputs = doc.CreateElement("JOB", "DOCINPUTS", "http://www.example.com");
job.AppendChild(docInputs);
XmlElement docInput = doc.CreateElement("JOB", "DOCINPUT", "http://www.example.com");
docInputs.AppendChild(docInput);
XmlElement docOutput = doc.CreateElement("JOB", "DOCOUTPUT", "http://www.example.com");
docOutputs.AppendChild(docOutput);
The current output:
<JOBS xmlns="http://www.example.com">
<JOB>
<JOB:DOCINPUTS xmlns:JOB="http://www.example.com">
<JOB:DOCINPUT />
</JOB:DOCINPUTS>
<JOB:DOCOUTPUTS xmlns:JOB="http://www.example.com">
<JOB:DOCOUTPUT />
</JOB:DOCOUTPUTS>
</JOB>
</JOBS>
However, my desired output is:
<JOBS xmlns:JOBS="http://www.example.com" xmlns:JOB="http://www.example.com">
<JOB>
<JOB:DOCINPUTS>
<JOB:DOCINPUT />
</JOB:DOCINPUTS>
<JOB:DOCOUTPUTS>
<JOB:DOCOUTPUT />
</JOB:DOCOUTPUTS>
</JOB>
</JOBS>
My question: how do I create an XmlDocument
that contains a root element with multiple namespaces?