libxml2 fails on xsd schema validation for element type anyURI containing special characters like “[”, “[”

纵然是瞬间 提交于 2020-01-24 17:51:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!