XML schema problem

blspider

Pripravnik
4. sep 2007
32
0
6
Pozdravljeni!

Imam problem z izdelavo scheme za validacijo naslednjega XML-ja:

Koda:
<?xml version="1.0" encoding="UTF-8"?>
<properties xmlns="http://www.site.com" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.site.com data.xsd">
  <menus>
    <menu pageId="1" data="abc"/>
    <menu pageId="2" data="def"/>
    <menu pageId="4" data="ghi"/>
  </menus>
  <pages>
    <page pageId="1" link="a"/>
    <page pageId="2" link="b"/>
    <page pageId="3" link="c"/>
  </pages>
</properties>

V schemi bi namreč rad dodal constraint, ki bo preveril ali ima vsak pageId iz elementa menu tudi ustrezno stran - pageId v elementu page. Se pravi zgornji xml ni veljaven (zaradi zadnjega menuja).

Probaval sem na vse mogoče načine ter bral specifikacije pa mi ne rata. Ve kdo kaj bi bilo narobe? Tole je shema:

Koda:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns="http://www.site.com" 
targetNamespace="http://www.site.com" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="properties">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="menus" type="menusType"/>
        <xs:element name="pages" type="pagesType"/>
      </xs:sequence>
    </xs:complexType>
    <xs:key name="pageKey">
      <xs:selector xpath="./pages/page"/>
      <xs:field xpath="@pageId"/>
    </xs:key>
    <xs:keyref refer="pageKey" name="menuRef">
      <xs:selector xpath="./menus/menu"/>
      <xs:field xpath="@pageId"/>
    </xs:keyref>
  </xs:element>
  <xs:complexType name="menusType">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="menu">
        <xs:complexType>
          <xs:attribute name="pageId" type="xs:positiveInteger" use="required"/>
          <xs:attribute name="data" type="xs:string" use="required"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="pagesType">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="page">
        <xs:complexType>
          <xs:attribute name="pageId" type="xs:positiveInteger" use="required"/>
          <xs:attribute name="link" type="xs:string" use="required"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Hvala!