如何通过C#代码在KML中写入引号

发布于 2024-12-22 15:20:53 字数 863 浏览 1 评论 0原文

也许这是一个愚蠢的问题,但我的 html 技能现在已经消失了..:)

我正在通过单击按钮创建一个 KML 文件,并且 KML 标签的所有代码都在那里。我需要的是使用多个标签。它将被硬编码在 KML 的开头。 KML 应如下所示:

KML with 2 Style id

因此,此代码是从后面的 C# 代码生成的。所以问题是如何

<Style id= "randomColorIcon">

在没有 id 部分的情况下像 /Style 一样获取然后正确关闭标签?

在 C# 代码中,我有类似的内容,但我发现它无法读取其他样式 id 标签,

kml.WriteStartElement("Style");
  kml.WriteElementString("id", "randomColorIcon"); //not suitable for more than one Style tags
  kml.WriteStartElement("IconStyle");
  kml.WriteStartElement("Icon");
  kml.WriteElementString("href",      "http://maps.google.com/mapfiles/kml/pal3/icon23.png");
  kml.WriteEndElement(); //</Icon>
  kml.WriteEndElement(); //</IconStyle> ??
  kml.WriteEndElement(); //</Style> 

提前致谢:)

maybe a stupid question here but my html skills are faded now.. :)

I am creating a KML file with a button click and all the code for the KML tags is there. What I need is using more than one tags. It will be hardcoded in the beginning of the KML. The KML should look something like this:

KML with 2 Style id

So this code is generated from the C# code behind. So the question is how to get

<Style id= "randomColorIcon">

and then close the tag properly like /Style without having the id part?

In the C# code I had something like this but I just found that it doesn't read the other Style id tags

kml.WriteStartElement("Style");
  kml.WriteElementString("id", "randomColorIcon"); //not suitable for more than one Style tags
  kml.WriteStartElement("IconStyle");
  kml.WriteStartElement("Icon");
  kml.WriteElementString("href",      "http://maps.google.com/mapfiles/kml/pal3/icon23.png");
  kml.WriteEndElement(); //</Icon>
  kml.WriteEndElement(); //</IconStyle> ??
  kml.WriteEndElement(); //</Style> 

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那一片橙海, 2024-12-29 15:20:53

就 XML 而言:

<Style id= "randomColorIcon"></Style>

和:

<Style id= "randomColorIcon" />

是等价的。

在这方面,以下内容将产生与您所要求的语义等效的内容:

kml.WriteStartElement("Style");
kml.WriteAttributeString("id", "randomColorIcon");
kml.WriteEndElement();

As far as XML is concerned:

<Style id= "randomColorIcon"></Style>

And:

<Style id= "randomColorIcon" />

Are equivalent.

In that respect, the following will produce the semantic equivalent of what you are asking for:

kml.WriteStartElement("Style");
kml.WriteAttributeString("id", "randomColorIcon");
kml.WriteEndElement();
你另情深 2024-12-29 15:20:53

您将需要 WriteAttributeString。

You'll need WriteAttributeString.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文