Créer de document XML par LINQ, ajouter xmlns,xmlns:xsi pour elle

J'essaie de créer un GPX XML document par LINQ to XML.

Tout fonctionne très bien, sauf l'ajout d'xmlns, xmlns:xsi attributs de la doc. En essayant de différente façon, je reçois différentes exceptions.

Mon code:

XDocument xDoc = new XDocument(
new XDeclaration("1.0", "UTF-8", "no"),
new XElement("gpx",
new XAttribute("creator", "XML tester"),
new XAttribute("version","1.1"),
new XElement("wpt",
new XAttribute("lat","7.0"),
new XAttribute("lon","19.0"),
new XElement("name","test"),
new XElement("sym","Car"))
));

La sortie doit également contenir ceci:

xmlns="http://www.topografix.com/GPX/1/1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"

Comment puis-je l'ajouter par Linq to XML? J'ai essayé plusieurs façons mais il ne fonctionne pas, des exceptions lors de la compilation.

OriginalL'auteur Tom | 2011-06-25