Error when trying to write an attribute string using XmlWriter

I am trying to write an attribute string like so: string kmlUrl = "http://www.opengis.net/kml/2.2"; using (XmlWriter writer = XmlWriter.Create(filePath, settings)) { await writer.WriteStartDocumentAsync(); writer.WriteStartElement("kml"); writer.WriteAttributeString("xmlns", $"{kmlUrl}"); // error here // rest of stuff } The element should look like this: <kml xmlns="http://www.opengis.net/kml/2.2"> However, I get the following error: "The prefix '' cannot be redefined from '' to 'http://www.opengis.net/kml/2.2' within the same start element tag." I'm confused why this is happening, because I do the same exact thing with other elements down the line without issue.
1 Reply
Nacho Man Randy Cabbage
Ahh just found this in the docs: "If the prefix is "xmlns" then this method also treats this as a namespace declaration and associates the declared prefix with the namespace URI provided in the given attribute value. In this case the ns argument can be null."