我尝试使用LINQ to XML创建一个GPX XML文档。
一切都很顺利,除了添加xmlns和xmlns:xsi属性到文档之外。我尝试了不同的方式,但是得到了不同的异常。
我的代码:
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"))
));
输出结果还应包括这个:
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"
我该如何使用Linq to XML添加它?我尝试了几种方法,但都没有成功,在编译期间会抛出异常。