gpt4 book ai didi

c# - 使用 C# 和 Linq 动态生成 kml 文件

转载 作者:数据小太阳 更新时间:2023-10-29 02:36:29 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How to set the default XML namespace for an XDocument

我正在尝试在 Asp.net C# 中编写一段代码,以便即时创建 KML 文件并将其存储在特定路径中。当我想添加 kml 标签的 xmlns="http://earth.google.com/kml/2.2"属性时,代码会出错(见下文)。我尝试用另一个词(如“id”)替换 xmlns,它工作得很好。它与“xmlns”这个词有关吗??!对我来说很奇怪。

如果您了解问题所在,请提供解决方案...谢谢!

我的代码:

XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", ""),
new XComment("This is comment by me"),
new XElement("kml", new XAttribute("xmlns", "http://earth.google.com/kml/2.2"),
new XElement("Document",
new XElement("Name", "something"), new XElement("Placemark",
new XAttribute("id", "1"),
new XElement("title", "something"),
new XElement("description", "something"),
new XElement("LookAt",
new XElement("Longitude", "49.69"),
new XElement("Latitude", "32.345")), new XElement("Point", new XElement("Coordinates", "49.69,32.345,0"))))));
doc.Save(Server.MapPath(@"~\App_Data\markers.xml"));

它给出的运行时错误:

The prefix '' cannot be redefined from '' to 'http://earth.google.com/kml/2.2' within the same start element tag. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The prefix '' cannot be redefined from '' to 'http://earth.google.com/kml/2.2' within the same start element tag.

我想创建的 kml 文件:

<?xml version="1.0" encoding="utf-8"?>
<!--This is comment by me-->
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Name>something</Name>
<Placemark id="1">
<title>something</title>
<description>something</description>
<LookAt>
<Longitude>49.69</Longitude>
<Latitude>32.345</Latitude>
</LookAt>
<Point>
<Coordinates>49.69,32.345,0</Coordinates>
</Point>
</Placemark>
</Document>
</kml>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com