marcintom
11-30-2008, 10:38 AM
I have :
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > <!-- xmlns="http://xx.pl/marcin" targetNamespace="http://xx.pl/marcin"> -->
<xs:annotation>
<xs:documentation xml:lang="pl">
Przykład schematu z rozszerzaniem typów i referencjami.
</xs:documentation>
</xs:annotation>
<xs:element name="studenci">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="student" type="StudentTyp"/>
<xs:element name="osoba" type="OsobaTyp"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="OsobaTyp">
<xs:sequence>
<xs:element name="imie" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="nazwisko" type="xs:string"/>
</xs:sequence>
<xs:attribute name="plec" type="PlecTyp" use="required"/>
<xs:attribute name="email" type="xs:string" use="optional"/>
</xs:complexType>
<xs:complexType name="StudentTyp">
<xs:complexContent>
<xs:extension base="OsobaTyp">
<xs:sequence>
<xs:element name="nr-indeksu" type="xs:unsignedLong"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="PlecTyp">
<xs:restriction base="xs:string">
<xs:enumeration value="k"/>
<xs:enumeration value="m"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="grupy">
<xs:complexType>
<xs:sequence>
<xs:element name="grupa" type="GrupaTyp" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="GrupaTyp">
<xs:sequence>
<xs:element name="numer-grupy" type="xs:positiveInteger"/>
<xs:element name="student" type="StudentWGrupieTyp" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="StudentWGrupieTyp">
<xs:attribute name="ref" type="xs:string"/>
</xs:complexType>
<xs:element name="uczelnia">
<xs:complexType>
<xs:sequence>
<xs:element ref="studenci"/>
<xs:element ref="grupy"/>
</xs:sequence>
</xs:complexType>
<xs:key name="studenci_key">
<xs:selector xpath="studenci/student"/>
<xs:field xpath="nr-indeksu"/>
</xs:key><!--
<xs:keyref name="grupy_studenci_ref" refer="studenci_key">
<xs:selector xpath="grupy/grupa/student"/>
<xs:field xpath="@ref"/>
</xs:keyref>-->
</xs:element>
</xs:schema>
and this work fine if the "nr-indeksu" is unique but if nr-indeksu is not unique there is an error in xml document
So this is good.
But when I tried to add xmlns="http://xx.pl/marcin" targetNamespace="http://xx.pl/marcin" to schema
The example xml documents with the same nr-indeksu is valid.
This is bad.
What can be wrong in my document.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > <!-- xmlns="http://xx.pl/marcin" targetNamespace="http://xx.pl/marcin"> -->
<xs:annotation>
<xs:documentation xml:lang="pl">
Przykład schematu z rozszerzaniem typów i referencjami.
</xs:documentation>
</xs:annotation>
<xs:element name="studenci">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="student" type="StudentTyp"/>
<xs:element name="osoba" type="OsobaTyp"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="OsobaTyp">
<xs:sequence>
<xs:element name="imie" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="nazwisko" type="xs:string"/>
</xs:sequence>
<xs:attribute name="plec" type="PlecTyp" use="required"/>
<xs:attribute name="email" type="xs:string" use="optional"/>
</xs:complexType>
<xs:complexType name="StudentTyp">
<xs:complexContent>
<xs:extension base="OsobaTyp">
<xs:sequence>
<xs:element name="nr-indeksu" type="xs:unsignedLong"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="PlecTyp">
<xs:restriction base="xs:string">
<xs:enumeration value="k"/>
<xs:enumeration value="m"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="grupy">
<xs:complexType>
<xs:sequence>
<xs:element name="grupa" type="GrupaTyp" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="GrupaTyp">
<xs:sequence>
<xs:element name="numer-grupy" type="xs:positiveInteger"/>
<xs:element name="student" type="StudentWGrupieTyp" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="StudentWGrupieTyp">
<xs:attribute name="ref" type="xs:string"/>
</xs:complexType>
<xs:element name="uczelnia">
<xs:complexType>
<xs:sequence>
<xs:element ref="studenci"/>
<xs:element ref="grupy"/>
</xs:sequence>
</xs:complexType>
<xs:key name="studenci_key">
<xs:selector xpath="studenci/student"/>
<xs:field xpath="nr-indeksu"/>
</xs:key><!--
<xs:keyref name="grupy_studenci_ref" refer="studenci_key">
<xs:selector xpath="grupy/grupa/student"/>
<xs:field xpath="@ref"/>
</xs:keyref>-->
</xs:element>
</xs:schema>
and this work fine if the "nr-indeksu" is unique but if nr-indeksu is not unique there is an error in xml document
So this is good.
But when I tried to add xmlns="http://xx.pl/marcin" targetNamespace="http://xx.pl/marcin" to schema
The example xml documents with the same nr-indeksu is valid.
This is bad.
What can be wrong in my document.