xs:anyURI可以在XSD中包含方括号吗?

时间:2017-01-27 11:35:16

标签: python xml xsd xsd-validation xml-validation

XML验证失败,错误:

  

元素'CategoryPageUrl':'http://www.example.com/products?my_query_parameter[]=45'不是原子类型'xs:anyURI'的有效值。,第29行

Feed看起来像这样:

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

适当的架构如下所示:

<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>

2 个答案:

答案 0 :(得分:5)

不,xs:anyURI不能包含方括号([])。

您的URI本身无效,而不仅仅是XSD ......

xs:anyURI跟随RFC 2396,经RFC 2732修改。

RFC 2396对URI的query部分有以下产品,您尝试使用方括号:

  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"

如您所见,[]不允许在那里。此外,方括号在URI中的任何位置通常被认为是 unwise ,每 2.4.3。排除的US-ASCII字符

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

RFC 2732确实使用[]定义了IPv6地址的语法,但这不在URI的query部分内。

答案 1 :(得分:0)

此外,RFC1738指出这些字符不安全