开发者

XML schema location best practices

After seeing quite some more cryptic error message, I realize they may be due to bogus URIs present here:开发者_Go百科

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:cxf="http://activemq.apache.org/camel/schema/cxfEndpoint"    
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://activemq.apache.org/camel/schema/spring
        http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
        http://activemq.apache.org/camel/schema/cxfEndpoint
        http://activemq.apache.org/camel/schema/cxf/cxfEndpoint.xsd
        http://cxf.apache.org/jaxws 
        http://cxf.apache.org/schemas/jaxws.xsd
        ">

Is it good practice to refer to online schemas?

From the above, for example:

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

works fine, which is all cute and well when you've got no Internet issue and when springframework.org is up etc. but then, from the above, there's also:

http://activemq.apache.org/camel/schema/cxf/cxfEndpoint.xsd

which gives:

"Oops! This link appears to be broken"

Oops indeed.

What are best practice regarding URIs referring to schema in a project?

Bonus question: how comes Eclipse doesn't complain in real-time about the broken links? (IntelliJ IDEA does it right!?)


Spring does not load the schemas over the net when starting up the container - there is a mechanism to embed the schemas within the jar files of Spring, and Spring uses these built-in schemas to validate the xml. This is applicable for all custom namespaces too.

Eclipse may complain, because Eclipse downloads the schemas based on the schema URI, which may not be hosted over the net, like in your case, there is a way to cache custom schemas within the Eclipse preferences also.


Take a look at the CatalogResolver: http://xml.apache.org/commons/components/apidocs/resolver/org/apache/xml/resolver/tools/CatalogResolver.html

May be it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜