日期:2014-05-18  浏览次数:20698 次

XML Schema的小问题,谢谢!
我用myeclipse写了一个XML Schema的小示例,但是myeclipse报错了,不知道为什么,请大家帮我看一下:


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="example4schema" elementFormDefault="qualified">

<xs:simpleType name="age_Type">
<xs:restriction base="xs:integer">
<xs:maxInclusive value="100" />
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>

<xs:element name="age" type="age_Type" /> <!-- 注意!!这句话报错了!-->
</xs:schema>


把刚才那一行去掉就没事了,报错的提示是:
src-resolve.4.1:Error resolving component 'age_Type'. It was detected that 'age_Type' has no namespace, but components with no target namespace are not referenceable from schema document 'file:///D:/workspace/XML_Schema/src/Test.xsd'. if 'age_Type' is intended to have a namespace, perhaps a predix needs to be provided. if it is intended that 'age_Type' has no namespace, then an 'import' without a 'namespace' attribute should be added to 'file:///D:/workspace/XML_Schema/src/Test.xsd'. 

感谢大家的帮助!

------解决方案--------------------
把targetNamespace去掉,targetNamespace有误。
------解决方案--------------------
你对你当前的schema文件设置了命名空间为  targetNamespace="example4schema" 

所以 ,如果你要引用你当前schema文件中申明的符合类型 也要使用example4schema最为前缀

将      <xs:element name="age" type="age_Type" />
改成
  <xs:element name="age" type="example4schema:age_Type" /> 即可

或者如1楼所说 将 targetNamespace="example4schema" 去掉 ,也是可以的
------解决方案--------------------
schema少了句:

xmlns:example4schema



<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.schema-demo.com" 
xmlns:car = "http://www.schema-demo.com"
elementFormDefault="qualified">
<xs:element name="car" type="car:carType">

</xs:element>

<xs:simpleType  name="carType">
<xs:restriction base="xs:string">
<xs:enumeration value="Audi" />
<xs:enumeration value="Golf" />
<xs:enumeration value="BMW" />
</xs:restriction>
</xs:simpleType>
</xs:schema>