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.
Was this page helpful?