在eclipse中用Rinzo插件编辑XML,生成了一个XSD,XML文件引用这个XSD,但我仍然可以输入任意元素或属性,属性的界定范围也不起作用,只要符合XML基本规范就不报错,这是怎么回事呢?
我打开Spring的配置文件xml,如果输入的属性或元素名不正确就立即显示红色,我看了它的schema文件也没看出问题来。

解决方案 »

  1.   

    我试了下:把spring的xsd文件下载到本地,把引用从原来的:
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    改为(beans.xsd是我保存到本地的):
    <beans orderid="889923"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="beans.xsd">
    也不行了,难道schema不能使用本地文件吗?
      

  2.   

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="beans.xsd">
    你的beans.xsd文件放在哪里?
      

  3.   

    noNamespaceSchemaLocation这种方式,我测试时和要编辑的XML文件放在一个目录下了。
    我传到一个网站上,用schemaLocation方式,能出来了,但报错如下:
    -schemaLocation value = 'http://www.dcharts.com/component.xsd' must have even number of  URI's.引用是这样写的:<?xml version="1.0" encoding="UTF-8"?>
    <components  xmlns="http://www.dcharts.com"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.dcharts.com/component.xsd">
    <component  name="" id="" instance-scope="SITE">
    ......
      

  4.   

    schemaLocation value = 'http://www.dcharts.com/component.xsd' must have even number of  URI's
    需要加版本号
      

  5.   

    我把component.xsd改名为component-1.0.xsd 了,引用中也改了,但还是老样子,怎么加版本号呢?
      

  6.   

    OK,解决了,使用schemaLocation,属性应为:“名称空间 空格 文件”,即:
     xsi:schemaLocation="http://www.dcharts.com  http://www.dcharts.com/component.xsd"