无法在 XMLElementName 中使用空格

发布于 2024-08-12 20:49:50 字数 174 浏览 2 评论 0原文

我正在使用 XMLwriter 创建 HTML,效果很好,但现在我需要放置图像标签,但我无法做到这一点 - 它仍然报告我无法在元素名称中使用“”。请高手指教如何解决,谢谢!

编辑:基本上,如何在 XML 文档中创建:

<img src="path" />

I am using XMLwriter to create HTML which works well, but now I need to place image tag but I am not able to do that - it still reports I cannot use ' ' in the element name. Please advice hwo to solve that, thanks!

EDIT: Basically, how to create in XML document this:

<img src="path" />

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

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

发布评论

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

评论(3

鸠书 2024-08-19 20:49:50

没错,XML 元素名称中不能有空格。

的情况下元素名称是img,然后有一个名称为src、值为path的属性。因此,元素名称中不需要空格,只需将其余部分呈现为属性,而不是尝试将其全部放入元素名称字段中。

It's right, you can't have a space in an XML element name.

In the case of <img src="path" /> the element name is img, then there's an attribute with a name of src and a value of path. So you don't need a space in your element name, you just need to render the rest of it as an attribute rather than trying to put it all in the element name field.

逐鹿 2024-08-19 20:49:50

嗯,这是绝对正确的 - XML 不能有空格“nofollow noreferrer”>元素名称,或者实际上是 HTML 元素名称。为什么你认为你需要它?图像标签的元素名称中没有空格...

您确定不想将空格放入属性值中吗?

您能给我们举个例子吗?

编辑:好的,所以在您的评论中您想要类似的内容:

<img src="path" />

这里:

  • img元素名称
  • src属性 name
  • path 是一个属性值

所以你可以使用类似的东西:

writer.WriteStartElement("img");
writer.WriteAttributeString("src", "path");
// Any extra bits you wanted
writer.WriteEndElement();

Well it's absolutely right - you can't have a space in an XML element name, or indeed in an HTML element name. Why do you think you need it? Image tags don't have spaces in the element name...

Are you sure you don't want to put the space in an attribute value?

Could you give us an example?

EDIT: Okay, so in your comment you want something like:

<img src="path" />

Here:

  • img is the element name
  • src is an attribute name
  • path is an attribute value

So you'd use something like:

writer.WriteStartElement("img");
writer.WriteAttributeString("src", "path");
// Any extra bits you wanted
writer.WriteEndElement();
沩ん囻菔务 2024-08-19 20:49:50

元素 name 必须遵循非常严格的规则。它必须遵循小于号 < (之后不能出现空格)。那么第一个字符不能是破折号、点或数量(以及其他一些)。最后是名称的其余部分,其中可能包含破折号或点。

XML + 命名空间的名称受到进一步限制。

An element name must follow very strict rules. It must follow the less-then sign < (after which NO space may occur). Then the first character cannot be a dash, a dot or a number (and some others). Finally the rest of the name follows which may include dashes or dots.

The name is further restricted for XML + Namespaces.

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