How to use Schema that is on local machine in XML document

前端 未结 1 1562
面向向阳花
面向向阳花 2020-12-13 19:37

I have limited knowledge of XML/Schema files.

So this should be a fairly simple question. How do you specify a local file for the schemaLocation?

<         


        
相关标签:
1条回答
  • 2020-12-13 20:15

    schemaLocation has to contain two values separated by whitespace: the namespace URI (this doesn't change) and the schema url.

    So in your case

     xsi:schemaLocation="http://www.w3schools.com ../relativepath/schemafolder/note.xsd">
    

    Don't be fooled by the namespace URI being a seemingly valid http url, that's just one of the little madnesses XML people invented. :)

    Actually, you can specify schemas for several namespaces in one schemaLocation:

    xsi:schemaLocation="namespace1 schemaurl1 namespace2 schemaurl2 ..."
    

    (I also advise you to use relative paths with care: while they are extremely useful when you move your files around but still validate it with the same code (or tool), when you deploy your validation code in an application, the "working directory" might not be what you expected. That is not to say you shouldn't use relative paths, just to be aware of this when you get a weird looking exception about the schema not found.)

    0 讨论(0)
提交回复
热议问题