Ajout d'espaces de noms pour XmlDocument à l'aide de XmlNamespaceManager

Je suis en train d'ajouter des espaces de noms pour un XmlDocument à l'aide de XmlNamespaceManager. C'est le xml en cours:

<?xml version="1.0"?>
<kml>
  <Document>
    <Placemark>
    </Placemark>
  </Document>
</kml>

Je voudrais le transformer à ce xml à l'aide du XmlNamespaceManager):

<?xml version="1.0"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
     xmlns:gx="http://www.google.com/kml/ext/2.2" 
     xmlns:kml="http://www.opengis.net/kml/2.2"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Document>
    <Placemark>
    </Placemark>
  </Document>
</kml>

Mais je ne suis pas en mesure de modifier le xml. Voici le code, je sais que ça doit être une solution facile:

public void addXmlns()
        {

            string xml = @"<?xml version=""1.0""?>
                    <kml>
                    <Document>
                    <Placemark>
                    </Placemark>
                    </Document>
                    </kml>";

            var xmldoc = new XmlDocument();

            xmldoc.LoadXml(xml);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmldoc.NameTable);

            //Add the namespaces
            nsmgr.AddNamespace("", "http://www.opengis.net/kml/2.2");
            nsmgr.AddNamespace("gx", "http://www.google.com/kml/ext/2.2");
            nsmgr.AddNamespace("kml", "http://www.opengis.net/kml/2.2");
            nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
            nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            string message;
            message = xmldoc.InnerXml;

            MessageBox.Show(message); //still shows the original xml

        }

Grâce Avant De La Main

Mise à jour #1 - Essayé, mais ça ne changera pas le XML:

public void addXmlns()
        {

            string xml = @"<?xml version=""1.0""?>
                    <kml>
                    <Document>
                    <Placemark>
                    </Placemark>
                    </Document>
                    </kml>";

            var xmldoc = new XmlDocument();

            xmldoc.LoadXml(xml);

            XmlSchema schema = new XmlSchema();
            schema.Namespaces.Add("", "http://www.opengis.net/kml/2.2");
            schema.Namespaces.Add("gx", "http://www.google.com/kml/ext/2.2");
            schema.Namespaces.Add("kml", "http://www.opengis.net/kml/2.2");
            schema.Namespaces.Add("atom", "http://www.w3.org/2005/Atom");
            schema.Namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xmldoc.Schemas.Add(schema);

            string message;
            message = xmldoc.InnerXml;

            MessageBox.Show(message); //still shows the original xml

        }
InformationsquelleAutor user3062349 | 2013-12-18