libxml2 在 xsd 元素类型 anyURI 的架构验证中失败,其中包含特殊字符,如“[”、“[”
libxml2 fails on xsd schema validation for element type anyURI containing special characters like "[", "["
我正在使用 go-libxml2 进行 xsd 模式验证。我有一个 XML 元素,它以 url 作为值。我的 xsd 还包含其类型为 anyURI,如下所示
<xs:element name="url" type="xs:anyURI">
以下代码在验证 url 时抛出错误,其中包含“[]”
xsd.schema.Validate(xml)
以下是抛出错误的示例url
<url>
<![CDATA[
http://example.com/orda/var[div]=super
]]>
</url>
错误:
'http://example.com/orda/var[div]=super is not a valid value of the atomic type 'xs:anyURI'
常规 url 工作正常。知道如何解决这个问题
参见RFC3986(强调我的):
A host identified by an Internet Protocol literal address, version 6
[RFC3513] or later, is distinguished by enclosing the IP literal
within square brackets ("[" and "]"). This is the only place where
square bracket characters are allowed in the URI syntax.
尝试将它们分别替换为 %5b
和 %5d
。
我正在使用 go-libxml2 进行 xsd 模式验证。我有一个 XML 元素,它以 url 作为值。我的 xsd 还包含其类型为 anyURI,如下所示
<xs:element name="url" type="xs:anyURI">
以下代码在验证 url 时抛出错误,其中包含“[]”
xsd.schema.Validate(xml)
以下是抛出错误的示例url
<url>
<![CDATA[
http://example.com/orda/var[div]=super
]]>
</url>
错误:
'http://example.com/orda/var[div]=super is not a valid value of the atomic type 'xs:anyURI'
常规 url 工作正常。知道如何解决这个问题
参见RFC3986(强调我的):
A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]"). This is the only place where square bracket characters are allowed in the URI syntax.
尝试将它们分别替换为 %5b
和 %5d
。