Created
April 5, 2018 14:49
-
-
Save hendisantika/a1d8d76479f6fd10eb42628070b51e98 to your computer and use it in GitHub Desktop.
Some XSD examples (and reminders!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<bank xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="bank.xsd"> | |
<accounts> | |
<savings_accounts> | |
<savings_account id="a1" interest="0.03"> | |
<balance>2500</balance> | |
</savings_account> | |
<savings_account id="a2" interest="0.03"> | |
<balance>15075</balance> | |
</savings_account> | |
</savings_accounts> | |
<checking_accounts> | |
<checking_account id="a3"> | |
<balance>4025</balance> | |
</checking_account> | |
<checking_account id="a4"> | |
<balance>-125</balance> | |
</checking_account> | |
<checking_account id="a5"> | |
<balance>325</balance> | |
</checking_account> | |
</checking_accounts> | |
</accounts> | |
<customers> | |
<customer id="c1"> | |
<name>Ben Richerdson</name> | |
<address>Park Drive 2</address> | |
</customer> | |
<customer id="c2"> | |
<name>Marc Wretcher</name> | |
<address>Mill Drive 75</address> | |
</customer> | |
<customer id="c3"> | |
<name>Angel Steady</name> | |
<address>Lake Sight 15</address> | |
</customer> | |
</customers> | |
<customer_accounts> | |
<customer_account c_id="c1" ac_id="a2"/> | |
<customer_account c_id="c1" ac_id="a3"/> | |
<customer_account c_id="c2" ac_id="a4"/> | |
<customer_account c_id="c3" ac_id="a1"/> | |
<customer_account c_id="c3" ac_id="a5"/> | |
</customer_accounts> | |
</bank> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<xs:element name="bank" type="bankType"> | |
<xs:key name="cIdKey"> | |
<xs:selector xpath="customers/customer"/> | |
<xs:field xpath="@id"/> | |
</xs:key> | |
<xs:keyref name="cIdKeyRef" refer="cIdKey"> | |
<xs:selector xpath="customer_accounts/customer_account"/> | |
<xs:field xpath="@c_id"/> | |
</xs:keyref> | |
<xs:key name="acIdKey"> | |
<xs:selector xpath="accounts/*/*"/> | |
<xs:field xpath="@id"/> | |
</xs:key> | |
<xs:keyref name="acidKeyRef" refer="acIdKey"> | |
<xs:selector xpath="customer_accounts/customer_account"/> | |
<xs:field xpath="@ac_id"/> | |
</xs:keyref> | |
<xs:unique name="uniqueCustomerId"> | |
<xs:selector xpath="customer"/> | |
<xs:field xpath="@id"/> | |
</xs:unique> | |
<xs:unique name="uniqueAccountId"> | |
<xs:selector xpath="accounts/savings_accounts/savings_account|accounts/checking_accounts/checking_account"/> | |
<xs:field xpath="@id"/> | |
</xs:unique> | |
</xs:element> | |
<xs:complexType name="bankType"> | |
<xs:all> | |
<xs:element name="accounts" type="accountsType"/> | |
<xs:element name="customers" type="customersType"/> | |
<xs:element name="customer_accounts" type="customerAccountsType"/> | |
</xs:all> | |
</xs:complexType> | |
<xs:complexType name="accountsType"> | |
<xs:all> | |
<xs:element name="savings_accounts" type="savingsAccountsType"/> | |
<xs:element name="checking_accounts" type="checkingAccountsType"/> | |
</xs:all> | |
</xs:complexType> | |
<xs:complexType name="checkingAccountsType"> | |
<xs:choice> | |
<xs:element name="checking_account" type="checkingAccountType" minOccurs="0" maxOccurs="unbounded"/> | |
</xs:choice> | |
</xs:complexType> | |
<xs:complexType name="savingsAccountsType"> | |
<xs:choice> | |
<xs:element name="savings_account" type="savingsAccountType" minOccurs="0" maxOccurs="unbounded"/> | |
</xs:choice> | |
</xs:complexType> | |
<xs:complexType name="checkingAccountType"> | |
<xs:complexContent> | |
<xs:extension base="baseAccountType"/> | |
</xs:complexContent> | |
</xs:complexType> | |
<xs:complexType name="savingsAccountType"> | |
<xs:complexContent> | |
<xs:extension base="baseAccountType"> | |
<xs:attribute name="interest" type="xs:decimal" use="required"/> | |
</xs:extension> | |
</xs:complexContent> | |
</xs:complexType> | |
<xs:complexType name="baseAccountType"> | |
<xs:sequence> | |
<xs:element name="balance" type="balanceType"/> | |
</xs:sequence> | |
<xs:attribute name="id" type="xs:string" use="required"/> | |
</xs:complexType> | |
<xs:simpleType name="balanceType"> | |
<xs:restriction base="xs:decimal"> | |
<xs:minExclusive value="-5000"/> | |
</xs:restriction> | |
</xs:simpleType> | |
<xs:complexType name="customersType"> | |
<xs:sequence> | |
<xs:element name="customer" type="customerType" minOccurs="0" maxOccurs="unbounded"/> | |
</xs:sequence> | |
</xs:complexType> | |
<xs:complexType name="customerType"> | |
<xs:all> | |
<xs:element name="name" type="xs:string"/> | |
<xs:element name="address" type="xs:string"/> | |
</xs:all> | |
<xs:attribute name="id" type="xs:string" use="required"/> | |
</xs:complexType> | |
<xs:complexType name="customerAccountsType"> | |
<xs:choice> | |
<xs:element name="customer_account" type="customerAccountType" minOccurs="0" maxOccurs="unbounded"/> | |
</xs:choice> | |
</xs:complexType> | |
<xs:complexType name="customerAccountType"> | |
<xs:attribute name="c_id" type="xs:string" use="required"/> | |
<xs:attribute name="ac_id" type="xs:string" use="required"/> | |
</xs:complexType> | |
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<book isbn="0836217462"> | |
<title> | |
Being a Dog Is a Full-Time Job | |
</title> | |
<author>Charles M. Schulz</author> | |
<character> | |
<name>Snoopy</name> | |
<friend-of>Peppermint Patty</friend-of> | |
<since>1950-10-04</since> | |
<qualification> | |
extroverted beagle | |
</qualification> | |
</character> | |
<character> | |
<name>Peppermint Patty</name> | |
<since>1966-08-22</since> | |
<qualification>bold, brash and tomboyish</qualification> | |
</character> | |
</book> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<xs:element name="book"> | |
<xs:complexType> | |
<xs:sequence> | |
<xs:element name="title"> | |
<xs:simpleType> | |
<xs:restriction base="xs:string"> | |
<xs:maxLength value="40"/> | |
</xs:restriction> | |
</xs:simpleType> | |
</xs:element> | |
<xs:element name="author"> | |
<xs:simpleType> | |
<xs:restriction base="xs:string"> | |
<xs:maxLength value="40"/> | |
</xs:restriction> | |
</xs:simpleType> | |
</xs:element> | |
<xs:element name="character" maxOccurs="unbounded" minOccurs="0"> | |
<xs:complexType> | |
<xs:sequence> | |
<xs:element name="name"> | |
<xs:simpleType> | |
<xs:restriction base="xs:string"> | |
<xs:maxLength value="40"/> | |
</xs:restriction> | |
</xs:simpleType> | |
</xs:element> | |
<xs:element name="friend-of" maxOccurs="unbounded" minOccurs="0"> | |
<xs:simpleType> | |
<xs:restriction base="xs:string"> | |
<xs:maxLength value="40"/> | |
</xs:restriction> | |
</xs:simpleType> | |
</xs:element> | |
<xs:element name="since" type="xs:date"/> | |
<xs:element name="qualification" type="xs:string"/> | |
</xs:sequence> | |
</xs:complexType> | |
</xs:element> | |
</xs:sequence> | |
<xs:attribute name="isbn" use="required"> | |
<xs:simpleType> | |
<xs:restriction base="xs:integer"> | |
<xs:totalDigits value="10"/> | |
</xs:restriction> | |
</xs:simpleType> | |
</xs:attribute> | |
</xs:complexType> | |
</xs:element> | |
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
movie, movie kind, movie maker, movie year, movie actors:before, movie actor, movie language, movie description, movie description:before , movie projections, movie projection, movie score { | |
display: block; | |
} | |
movie { | |
font-family: Times New Roman; | |
font-size: 12pt; | |
} | |
movie title { | |
font-size: 14pt; | |
font-style: bold; | |
} | |
movie duration:before { | |
content: "("; | |
} | |
movie duration:after { | |
content: "min)"; | |
} | |
movie kind:before { | |
content: "Genre : "; | |
} | |
movie maker, movie year { | |
color: red; | |
} | |
movie maker:before { | |
color: black; | |
content: "De : "; | |
} | |
movie year:before { | |
color: black; | |
content: "Année : "; | |
} | |
movie actors { | |
color: blue; | |
font-style: italic; | |
} | |
movie actors:before { | |
color: black; | |
content: "Avec : "; | |
font-style: normal; | |
} | |
movie language:before { | |
content: "Langue : "; | |
} | |
movie description:before { | |
content: "Synopsis : "; | |
} | |
movie description:before { | |
content: "Synopsis : "; | |
} | |
movie projections:before { | |
content: "Séances : "; | |
} | |
movie projection { | |
content: "Séances : "; | |
} | |
movie projection[day="Lundi"]:before { | |
content: "Lundi : "; | |
} | |
movie projection[day="Mardi"]:before { | |
content: "Mardi : "; | |
} | |
movie projection[day="Mercredi"]:before { | |
content: "Mercredi : "; | |
} | |
movie projection[day="Jeudi"]:before { | |
content: "Jeudi : "; | |
} | |
movie projection[day="Vendredi"]:before { | |
content: "Vendredi : "; | |
} | |
movie projection[day="Samedi"]:before { | |
content: "Samedi : "; | |
} | |
movie projection[day="Dimanche"]:before { | |
content: "Dimanche : "; | |
} | |
movie score:before { | |
content: "Note : "; | |
} | |
movie score press:after { | |
content: "/5(Presse),"; | |
} | |
movie score spectators:after { | |
content: "/5(Spectateurs)"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE movies [ | |
<!ELEMENT movies (movie*)> | |
<!ELEMENT movie (title, duration, kind, maker, actors, year, language, description, projections, score?)> | |
<!-- Pour être indépendant de l'ordre il faudrait utilisé | |
((title, duration, kind, maker, actors, year, language, description, projections, score?)| | |
(duration, title, kind, maker, actors, year, language, description, projections, score?)| | |
(duration, kind, title, maker, actors, year, language, description, projections, score?)| | |
... | |
) --> | |
<!ELEMENT title (#PCDATA)> | |
<!ELEMENT duration (#PCDATA)> | |
<!ELEMENT kind (#PCDATA)> | |
<!ELEMENT maker (#PCDATA)> | |
<!ELEMENT actors (actor*)> | |
<!ELEMENT actor (#PCDATA)> | |
<!ELEMENT year (#PCDATA)> | |
<!ELEMENT language (#PCDATA)> | |
<!ELEMENT description (#PCDATA)> | |
<!ELEMENT projections (projection+)> | |
<!ELEMENT projection (time+)> | |
<!ELEMENT time (#PCDATA)> | |
<!ELEMENT score (press?, spectators?)> | |
<!ELEMENT press (#PCDATA)> | |
<!ELEMENT spectators (#PCDATA)> | |
<!ATTLIST projection day CDATA #REQUIRED> | |
]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE movies SYSTEM "cinema.dtd"> | |
<?xml-stylesheet href="cinema.css" type="text/css"?> | |
<movies> | |
<movie> | |
<title>Les Brigades du Tigre</title> | |
<duration>2h05</duration> | |
<kind>Thriller</kind> | |
<maker>Jérôme Cornuau</maker> | |
<actors> | |
<actor>C. Cornillac</actor> | |
<actor>D. Kruger</actor> | |
<actor>E. Baer</actor> | |
</actors> | |
<year>2005</year> | |
<language>Français</language> | |
<description>Les aventures du commissaire Valentin et des inspecteurs Terrasson et Pujol, membres des Brigades mobiles, corps spécial de la police française créé avant la Première Guerre mondiale.</description> | |
<projections> | |
<projection day="Lundi"> | |
<time>14h00</time> | |
<time>19h40</time> | |
<time>22h10</time> | |
</projection> | |
<projection day="Mardi"> | |
<time>14h00</time> | |
<time>19h40</time> | |
<time>22h10</time> | |
</projection> | |
<projection day="Mercredi"> | |
<time>14h00</time> | |
<time>16h40</time> | |
<time>19h40</time> | |
<time>22h10</time> | |
</projection> | |
<projection day="Jeudi"> | |
<time>14h00</time> | |
<time>19h40</time> | |
<time>22h10</time> | |
</projection> | |
<projection day="Vendredi"> | |
<time>14h00</time> | |
<time>19h40</time> | |
<time>22h10</time> | |
</projection> | |
<projection day="Samedi"> | |
<time>14h00</time> | |
<time>16h40</time> | |
<time>19h40</time> | |
<time>22h10</time> | |
</projection> | |
<projection day="Dimanche"> | |
<time>10h20</time> | |
<time>14h00</time> | |
<time>16h40</time> | |
<time>20h20</time> | |
</projection> | |
</projections> | |
<score> | |
<press>3</press> | |
<spectators>4</spectators> | |
</score> | |
</movie> | |
</movies> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment