如何包含[在xml元素名称中(How to include [ in xml element name)

编程入门 行业动态 更新时间:2024-10-11 03:22:59
如何包含[在xml元素名称中(How to include [ in xml element name)

有没有办法在[xml元素名称中包含] [字符?

例如

<AWSECommerceService.ItemSearch.ItemSearch.Request[0].SearchIndex>Electronics</AWSECommerceService.ItemSearch.ItemSearch.Request[0].SearchIndex>

使用它的原因是在SVG中,隐藏请求输入值是使用名称指定请求键的xml元素指定的。

例如:

<xforms:model id="form1"> <xforms:instance> <q>toyota</q> </xforms:instance> <xforms:submission id="submit1" xforms:method="get" xforms:action="http://www.google.ca/search" />

会产生对http://www.google.ca/search?q=toyota的请求

Is there any way to include the [ character in an xml element name?

For example

<AWSECommerceService.ItemSearch.ItemSearch.Request[0].SearchIndex>Electronics</AWSECommerceService.ItemSearch.ItemSearch.Request[0].SearchIndex>

The reason for using this is that in SVG hidden request input values are specified using xml elements whose name specifies the request key.

For example:

<xforms:model id="form1"> <xforms:instance> <q>toyota</q> </xforms:instance> <xforms:submission id="submit1" xforms:method="get" xforms:action="http://www.google.ca/search" />

would result in a request to http://www.google.ca/search?q=toyota

最满意答案

你不能 - 它不是XML元素名称的有效部分。

从规格 :

ASCII符号和标点符号以及相当大的一组Unicode符号字符从名称中排除,因为它们在XML文档外部使用XML名称的上下文中更有用作为分隔符。 提供此组为这些上下文提供了有关不能成为XML名称一部分的内容的硬性保证。

然后BNF遵循允许的内容:

NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] Name ::= NameStartChar (NameChar)* Names ::= Name (#x20 Name)* Nmtoken ::= (NameChar)+ Nmtokens ::= Nmtoken (#x20 Nmtoken)*

You can't - it's not a valid part of an XML element name.

From the spec:

The ASCII symbols and punctuation marks, along with a fairly large group of Unicode symbol characters, are excluded from names because they are more useful as delimiters in contexts where XML names are used outside XML documents; providing this group gives those contexts hard guarantees about what cannot be part of an XML name.

There then follows BNF for what is allowed:

NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] Name ::= NameStartChar (NameChar)* Names ::= Name (#x20 Name)* Nmtoken ::= (NameChar)+ Nmtokens ::= Nmtoken (#x20 Nmtoken)*

更多推荐

本文发布于:2023-07-30 15:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338835.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   名称   xml   include   element

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!