Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can xs:anyURI contain square brackets in XSD?

XML Validation fails with error:

Element 'CategoryPageUrl': 'http://www.example.com/products?my_query_parameter[]=45' is not a valid value of the atomic type 'xs:anyURI'., line 29

Feed looks like this:

    <Category>
        <ExternalId>1234</ExternalId>
        <Name>Name</Name>
        <CategoryPageUrl>http://www.example.com/products?my_query_parameter[]=45</CategoryPageUrl>
    </Category>

Appropriate piece of schema looks like this:

<xs:complexType name="CategoryType">
  <xs:all>
    <xs:element name="ExternalId" type="ExternalIdType" minOccurs="0"/>
    <xs:element name="Name" type="xs:string" minOccurs="0"/>
    <xs:element name="CategoryPageUrl" type="xs:anyURI" minOccurs="0"/>
  </xs:all>
</xs:complexType>
like image 326
Enthusiastic Developer Avatar asked Jan 27 '17 11:01

Enthusiastic Developer


People also ask

What does Xs mean in XSD?

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/>

What is XS anyURI?

Description. This datatype corresponds normatively to the XLink href attribute. Its value space includes the URIs defined by the RFCs 2396 and 2732, but its lexical space doesn't require the character escapes needed to include non-ASCII characters in URIs.

What does Xs mean in XML?

1.1 The Schema Namespace ( xs ) The XML representation of schema components uses a vocabulary identified by the namespace name http://www.w3.org/2001/XMLSchema . For brevity, the text and examples in this specification use the prefix xs: to stand for this namespace; in practice, any prefix can be used.

How an element can be defined within an XSD?

Each element definition within the XSD must have a 'name' property, which is the tag name that will appear in the XML document. The 'type' property provides the description of what type of data can be contained within the element when it appears in the XML document.


1 Answers

No, a xs:anyURI cannot contain square brackets ([ or ]).

Your URI itself is invalid, and not just to XSD...

xs:anyURI follows RFC 2396, as amended by RFC 2732.

RFC 2396 has the following productions for the query portion of URI, where you're attempting to use square brackets:

  query         = *uric
  uric          = reserved | unreserved | escaped
  reserved      = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                  "$" | ","
  unreserved    = alphanum | mark
  mark          = "-" | "_" | "." | "!" | "~" | "*" | "'" |
                  "(" | ")"

  escaped       = "%" hex hex
  hex           = digit | "A" | "B" | "C" | "D" | "E" | "F" |
                          "a" | "b" | "c" | "d" | "e" | "f"

  alphanum      = alpha | digit
  alpha         = lowalpha | upalpha

  lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
             "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
             "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
  upalpha  = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
             "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
             "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
  digit    = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
             "8" | "9"

As you can see, [ and ] are not allowed there. Further, square brackets are generally considered to be unwise anywhere in a URI, per 2.4.3. Excluded US-ASCII Characters:

unwise      = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"

RFC 2732 does define a syntax for IPv6 address using [ and ], but that's not within the query portion of a URI.

like image 80
kjhughes Avatar answered Sep 22 '22 16:09

kjhughes