tags:

views:

88

answers:

2

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

+4  A: 

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)*
Jon Skeet
Thanks for the answer!That's a serious limitation of svg xforms then since you might need request parameters that have [ in their name and I couldn't find any other way to include hidden parameters in a request than by defining xforms elements (xml elements) that are not tied to a UI control
+3  A: 

Not possible. The XML spec defines an element name as being a NameStartChar followed by NameChars and neither of those contain square brackets

Gareth