Kurs XML - Zadanie 6.

Treść

Przygotuj schemat XMLSchema opisujacy język znaczników do przechowywania informacji o wynikach pracowni. Utwórz przykładowy dokument XML.

Wykorzystaj nowe możliwości:

  • umieść definiowany język znaczników w przestrzeni nazw,
  • użyj facets do zdefiniowania formatu numeru tel., emaila, itp.
  • bądź elastyczny w sprawie umiejscowienia komentarzy,
  • dopuść takie znaczniki w opisach jak: em, strong, a (z przestrzeni nazw http://www.w3.org/1999/xhtml)
  • oceniane będzie też użycie innych możliwości XML Schema (wypróbuj 2-3 inne nowości).

Rozwiązanie (Ponton)

pracownia.xsd
<?xml version="1.0"?>
 
<xs:schema      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns="http://www.przestrzennazw.pl"
                targetNamespace="http://www.przestrzennazw.pl"
                xmlns:xhtml="http://www.w3.org/1999/xhtml"
                elementFormDefault="unqualified">
 
  <xs:import    namespace="http://www.w3.org/1999/xhtml"
                schemaLocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd"/>
 
  <xs:element name="imie" type="xs:string"/> 
  <xs:element name="nazwisko" type="xs:string"/>
  <xs:element name="punkty" type="xs:integer"/>
  <xs:element name="mail">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="[^@]+@[^@]+"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
 
  <xs:element name="em" type="xhtml:xhtml.em.type"/>
  <xs:element name="a" type="xhtml:xhtml.a.type"/>
  <xs:element name="strong" type="xhtml:xhtml.strong.type"/>
 
  <xs:element name="komentarz">
    <xs:complexType mixed="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="a"/>
        <xs:element ref="strong"/>
        <xs:element ref="em"/>        
      </xs:choice>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="zadanie">
    <xs:complexType>
      <xs:all>
        <xs:element ref="punkty"/> 
        <xs:element ref="komentarz"/>
      </xs:all>
      <xs:attribute name="nr" type="xs:integer"/>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="grupa">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="student" minOccurs="1" maxOccurs="unbounded"/> 
      </xs:sequence>
      <xs:attribute name="rodzaj" type="xs:string" default="podstawowa"/>
    </xs:complexType>
  </xs:element>
 
 
  <xs:element name="lista">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="zadanie" minOccurs="1" maxOccurs="unbounded"/> 
      </xs:sequence>
      <xs:attribute name="nr" type="xs:integer"/>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="student">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="imie"/> 
        <xs:element ref="nazwisko"/>
        <xs:element ref="mail"/>
        <xs:element ref="lista" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="pracownia">
    <xs:complexType> 
      <xs:sequence> 
        <xs:element ref="grupa" minOccurs="1" maxOccurs="unbounded"/> 
      </xs:sequence> 
    </xs:complexType>
  </xs:element> 
 
</xs:schema>
pracownia.xml
<?xml version="1.0"?>
<pracownia xmlns="http://www.przestrzennazw.pl"> 
 
  <grupa>
     <student>
       <imie>Jan</imie> 
       <nazwisko>Kowalski</nazwisko>
       <mail>jan@kowalski.pl</mail>
       <lista nr="1">
        <zadanie nr="2">
         <punkty>5</punkty>
         <komentarz><strong>Bardzo</strong> dobrze, <em>Janie</em>. <a href="http://www.google.pl">Google</a>...</komentarz>
        </zadanie>
       </lista>
     </student>
  </grupa>
 
</pracownia>
 
kurs_xml/10.zadanie06.txt · ostatnio zmienione: 2010/03/28 11:29 przez d
 
Wszystkie treści w tym wiki, którym nie przyporządkowano licencji, podlegają licencji:MIT License
Recent changes RSS feed