NOTE I am limited to .NET 2.0
I need to add a namespace using a XmlTextWriter. I am not reading in a Xml Document or saving it out. At first I was thinking I could use the XmlNameSpaceManager to add a namespace, but this appears to be in the case I have read in a xml document or working with an XmlDocument object.
Maybe I am over complicating this as I will only be dealing with one namespace at a time. It appears I could just add a root element with an attribute to manually create the namespace since it is on the root element.
An Example of what I need to create:
<?xml version="1.0" encoding="utf-8"?>
<abcElement xmlns="urn:schemas-acme-com:transaction-data-1.1">
</abcElement>
Would there be a problem with doing something like:
xtw.WriteStartDocument();
xtw.WriteStartElement("abcElement");
xtw.WriteAttributeString("xmlns", "urn:schemas-acme-com:transaction-data-1.1");
xtw.WriteEndElement();
Or is there an issue with this?
You should not try to output xmlns by hand. Use another overide of WriteStartElement instead – http://msdn.microsoft.com/en-us/library/7cdfkth5.aspx