问题
I am using go-libxml2 for my xsd schema validation. I have an XML element which takes url as a value. My xsd also contains its type as anyURI as follows
<xs:element name="url" type="xs:anyURI">
The following code throws error on validation url which contains "[]"
xsd.schema.Validate(xml)
The following is the sample url which throws an error
<url>
<![CDATA[
http://example.com/orda/var[div]=super
]]>
</url>
Error:
'http://example.com/orda/var[div]=super is not a valid value of the atomic type 'xs:anyURI'
Regular urls are working fine. Any idea how to solve this issue
回答1:
See RFC3986 (emphasis mine):
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.
Try replacing them with %5b
and %5d
, respectively.
来源:https://stackoverflow.com/questions/57972627/libxml2-fails-on-xsd-schema-validation-for-element-type-anyuri-containing-specia