Is there a way to create this XML with the .NET XML namespace methods? The elements below <fld2> are namespace qualified
<root>
<fld1>
</fld1>
<fld2 xmlns:tjh="http://test.com">
<tjh:fld3>stuff</tjh:fld3>
<tjh:fld4>stuff</tjh:fld4>
</fld2>
</root>
When I use
XmlElement fld = xDoc.CreateElement("tjh:fld2");
-or-
XmlElement fld = xDoc.CreateElement("tjh:fld2", "");
-or-
XmlElement fld= xDoc.CreateElement("tjh", "fld2", null);
-or-
XmlElement fld= xDoc.CreateElement("tjh", "fld2", "");
fld.prefix is 'tjh'
fld.Name is 'tjh:fld2'
However fld.OuterXml generates <fld2/> the prefix is not present
When I use
XmlElement fld = xDoc.CreateElement("tjh:fld2", "http://test.com")
-or-
XmlElement fld= xDoc.CreateElement("tjh", "fld2", "http://test.com");
fld.OuterXml generates "<tjh:fld2 xmlns:tjh=\"http://test.com\" />"; The prefix is present, but the extraneous xmlns attribute is applied to every element in the document. Since the xmlns is declared on the parent node, I don't think it needs to be emitted on all the child nodes?
<root>
<fld1>
</fld1>
<fld2 xmlns:tjh="http://test.com">
<tjh:fld3>stuff</tjh:fld3>
<tjh:fld4>stuff</tjh:fld4>
</fld2>
</root>
When I use
XmlElement fld = xDoc.CreateElement("tjh:fld2");
-or-
XmlElement fld = xDoc.CreateElement("tjh:fld2", "");
-or-
XmlElement fld= xDoc.CreateElement("tjh", "fld2", null);
-or-
XmlElement fld= xDoc.CreateElement("tjh", "fld2", "");
fld.prefix is 'tjh'
fld.Name is 'tjh:fld2'
However fld.OuterXml generates <fld2/> the prefix is not present
When I use
XmlElement fld = xDoc.CreateElement("tjh:fld2", "http://test.com")
-or-
XmlElement fld= xDoc.CreateElement("tjh", "fld2", "http://test.com");
fld.OuterXml generates "<tjh:fld2 xmlns:tjh=\"http://test.com\" />"; The prefix is present, but the extraneous xmlns attribute is applied to every element in the document. Since the xmlns is declared on the parent node, I don't think it needs to be emitted on all the child nodes?