我尝试通过 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 将其添加到 XML?我尝试了几种方法,但它不起作用,编译时出现异常。