Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: Общие вопросы > Xsd - уникальность атрибута


Автор: Avtarkia 6.4.2009, 10:01
Есть xml-файл, в котором у разных item-тегов имеется атрибут id, нужно обеспечить его уникальность:
Код

<?xml version="1.0" encoding="utf-8" ?>
<root>
 <item id="1" name="n1" />
 <item id="2" name="n2"  />
 <item id="1" name="n3" />
</root>

Вот схема:
Код

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="root">
  <xs:complexType>
   <xs:sequence>
    <xs:element maxOccurs="unbounded" name="item" type="itemType"/>
   </xs:sequence>
  </xs:complexType>
  <xs:unique name="uniqueID">
   <xs:selector xpath="item"/>
   <xs:field xpath="@id"/>
  </xs:unique>
 </xs:element>
 <xs:complexType  name="itemType">
  <xs:attribute name="id" type="xs:unsignedByte" use="required" />
  <xs:attribute name="name" type="xs:string" use="required" />
 </xs:complexType>
</xs:schema>


Этот пример взят в форума http://www.gotdotnet.ru/Forums/Web/514911.aspx . Моя схема больше,но проблема такая же, а именно:
эклипс говорит вот что: 
 src-resolve.4.2: Error resolving component 'itemType'. It was detected that 'itemType' is in namespace 
 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from 
 schema document 'file:///.../example.xsd'. If this is the 
 incorrect namespace, perhaps the prefix of 'itemType' needs to be changed. If this is the correct 
 namespace, then an appropriate 'import' tag should be added to 'file:///.../example.xsd'. 
Добаление тега не помогло (добавлялся сразу после тега <schema>)
Код

<import namespace="file:///.../example.xsd"/>

Как с этим справиться?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)