“/”的 XML 实体?

发布于 2024-07-13 08:38:45 字数 170 浏览 4 评论 0原文

因此,我正在编写一些 XML 生成代码,并发现以下属性值搞乱了 XML 格式:

"Jim/Bob"

因此,我研究了用作转义序列的 XML 实体,我看到的每个列表都不包含正斜杠。 我在这里遗漏了一些明显的东西吗? 看起来像是你想要逃避的事情......

So I'm writing some XML generating code, and found that the following attribute value was screwing up the XML formatting:

"Jim/Bob"

So I looked into the XML Entities used as escape sequences and every list I saw did not include one for the forward slash. Am I missing something obvious here? Seems like the sort of thing you'd want to escape...

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

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

发布评论

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

评论(7

眼睛会笑 2024-07-20 08:38:45

正斜杠按原样有效,不需要进一步编码。

唯一保留的字符是:

>
<
&
%

对于更多 XML 实体 - http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

The forward slash is valid as is and does not need further encoding.

The only reserved characters are:

>
<
&
%

For even more XML entities - http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

時窥 2024-07-20 08:38:45

我知道事实证明这不是问题,但我认为除了 bobince 的答案之外,提到 Fraction Slash HTML 实体 ⁄ 看起来就像正斜杠。 以防万一到达此页面的任何人实际上确实想要一个代表正斜杠的 HTML 实体。

I know it turned out this wasn't the problem, but I thought it would be helpful to mention that, in addition to bobince's answer, the Fraction Slash HTML entity looks just like a forward slash. Just in case anybody reaching this page actually does want an HTML entity for something representing a forward slash.

深陷 2024-07-20 08:38:45

我认为该线程中的注释并不完全正确,因为如果您使用架构 (XSD),您可以定义名称为 Jim、Bob 和 Jim/Bob 的元素,而不会出现任何问题。 但是当您想要定义元素和实体时:

<names>
  <Jim>Carrey</Jim>
  <Bob>Jones</Bob>
  <Jim/Bob>Six figured Hillbilly</Jim/Bob>
</names>

问题就很明显了。

I don't think the comments in this thread are entirely correct since if you use a schema (XSD) you could define elements with names Jim, Bob and Jim/Bob without any issues. But then when you want to define the element and entity:

<names>
  <Jim>Carrey</Jim>
  <Bob>Jones</Bob>
  <Jim/Bob>Six figured Hillbilly</Jim/Bob>
</names>

The problems are obvious.

苄①跕圉湢 2024-07-20 08:38:45

仅供参考,尽管斜杠是有效的 XML,但请注意下游如何使用它。 我们用它来连接到天蓝色服务总线队列。 Azure 本身在连接字符串中生成了带有斜杠的密钥,但当我们尝试使用它们时却悄无声息地崩溃了。 使用 “/” 转义它们使其起作用

"Jim/Bob"

FYI although a slash is valid XML, watch out how it's being used downstream. We used it for connecting to an azure service bus queue. Azure itself generated keys with slashes in the connection strings, but then broke silently when we tried to use them. Escaping them with “/” made it work

"Jim/Bob"
蛮可爱 2024-07-20 08:38:45

没有预定义的实体引用,但您可以使用字符引用:“/”。

但是,您不需要转义 / 来包含在 XML 中。 您可能必须将其包含在其他内容中,例如 URI 路径部分。 但随后你必须先将其转义为该格式; 获取 URI 的应用程序无法知道您是否已将其编码到 XML 中。

There's no predefined entity reference for it, but you can use a character reference: “/”.

However, you don't need to escape / for inclusion in XML. You might have to include it for inclusion in something else, for example a URI path part. But then you'd have to escape it for that format first; the application that picks up the URI wouldn't have any way to know if you'd encoded it in the XML or not.

执笔绘流年 2024-07-20 08:38:45

我不明白为什么“Jim/Bob”的值需要转义或导致 XML 出现任何问题。

I can't see why a value of "Jim/Bob" would need escaping or cause XML any problems at all.

捂风挽笑 2024-07-20 08:38:45

您可能有一个受约束的属性,如 XML 架构中所定义。

我不知道你所说的 XML 格式是什么意思。

You probably have a constrained attribute, as defined in the XML Schema.

I do not know what you mean by XML formatting.

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