gpt4 book ai didi

python - 可以 xs :anyURI contain square brackets in XSD?

转载 作者:数据小太阳 更新时间:2023-10-29 01:56:24 25 4
gpt4 key购买 nike

XML 验证 失败并出现错误:

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

提要看起来像这样:

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

最佳答案

不可以,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"

如您所见,[] 在那里是不允许的。此外,根据 2.4.3,方括号通常被认为在 URI 中的任何地方都是不明智的。排除的 US-ASCII 字符:

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

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

关于python - 可以 xs :anyURI contain square brackets in XSD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41893073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com