Academic Tutorials



English | French | Portugese | Dutch | Italian
Google

on-line

Haupt Quellenprogramme E-Bücher Downloads Mit uns in Verbindung treten Über uns

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting


Ein XSD Beispiel

Previous Next




Dieses Kapitel zeigt, wie man ein XML Schemata schreibt. Du erfährst auch, daß ein xml Schema in unterschiedliche Weisen geschrieben werden kann.



Ein XML Dokument

Lassen Sie uns einen Blick an den dieses XML Dokumenten haben, die „shiporder.xml genannt werden,“:

<?xml version="1.0" encoding="ISO-8859-1"?>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>

Das XML Dokument oben bestehen aus einem Wurzelelement, „shiporder“, das ein erforderliches Attribut enthält, das „orderid“ genannt wird. Das „shiporder“ Element enthalten drei unterschiedliche Kindelemente: „orderperson“, „shipto“ und „Einzelteil“. Das „Einzelteil“ Element erscheinen zweimal, und es enthält „Titel“, ein wahlweise freigestelltes „Anmerkung“ Element, „Quantität“ und ein „Preis“ Element.

Die Linie oben: xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance „erklärt der XML grammatischen Definition, daß dieses sollte gegen ein Schema validiert werden dokumentiert. Die Linie: xsi: noNamespaceSchemaLocation= " shiporder.xsd“ spezifizieren, WO das Schema liegt (hier ist es im gleichen Heft wie „shiporder.xml“).



Ein XML Schema herstellen

Jetzt möchten wir ein Schema für das XML Dokument oben herstellen.

Wir beginnen, indem wir eine neue Akte öffnen, die wir benennen als „shiporder.xsd“. Um das Schema herzustellen könnten wir der Struktur in den XML Dokumenten einfach folgen und jedes Element definieren wie wir es finden. Wir beginnen mit der Standard-XML Erklärung, die von den xs gefolgt wird: Schemaelement, das ein Schema definieren:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
...
...
</xs:schema>

Im Schema oben benutzen wir das Standardnamespace (xs), und der URI, der mit diesem namespace verbunden ist, ist die Schemasprachendefinition, die den Standardwert von http://www.w3.org/2001/XMLSchemas hat.

Zunächst müssen wir „shiporder“ Element definieren. Dieses Element läßt ein Attribut und es andere Elemente enthalten, folglich halten wir es für eine komplizierte Art. Das Kindelement des „shiporder“ Elements wird durch xs umgeben: Element der Reihe nach ordnen, das eine bestellte Reihenfolge der Vorelemente definiert:

<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
...
...
</xs:sequence>
...
</xs:complexType>
</xs:element>

Dann müssen wir das „orderperson“ Element als einfache Art definieren (weil sie keine Attribute oder andere Elemente enthält). Die Art (xs: Zeichenkette) wird mit dem namespace Präfix vorgesetzt, das mit XML Schemata verbunden ist, das eine vorbestimmte Schemadatenart anzeigt:

<xs:element name="orderperson" type="xs:string"/>

Zunächst müssen wir definieren zwei Elemente, die von der komplizierten Art sind: „shipto“ und „Einzelteil“. Wir beginnen, indem wir das „shipto“ Element definieren, wie folgt:

<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Mit Schema können wir die Zahl möglichem Auftreten für ein Element mit den maxOccurs und den minOccurs Attributen definieren. maxOccurs spezifizieren die Höchstzahl des Auftretens für ein Element und minOccurs spezifiziert die Mindestzahl des Auftretens für ein Element. Der Default-Wert für beide maxOccurs und minOccurs ist immer 1!

Jetzt können wir „Einzelteil“ Element definieren. Dieses Element kann erscheinen mehrfache Zeiten innerhalb des „shiporder“ Elements. Dieses wird spezifiziert, indem man das maxOccurs Attribut des „Einzelteil“ Elements „unbegrenzt“ einstellt, die bedeuten, daß es da vieles Auftreten des „Einzelteil“ Elements geben kann, wie der Autor wünscht. Beachten, daß das „Anmerkung“ Element hier wahlweise freigestellt ist. Wir haben dieses spezifiziert, indem wir das minOccurs Attribut einstellten, um null zu sein:

<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Wir können das Attribut „shiporder“ des Elements jetzt erklären. Da dieses ein erforderliches Attribut ist, spezifizieren wir " das erforderte“ use=.

Anmerkung: Die Attributerklärung muß immer zuletzt kommen:

<xs:attribute name="orderid" type="xs:string" use="required"/>

Ist hier die komplette Auflistung der Schemaakte, die das „shiporder.xsd“ genannt wird:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>


Das Schema teilen

Die vorhergehende Designmethode ist sehr einfach, aber kann schwierig sein, zu lesen und beizubehalten, wann Dokument kompliziert sind.

Die folgende Designmethode basiert auf alle Elemente und Attribute zuerst definieren, und auf sie dann sich beziehen die Bezugsattribute verwendend.

Ist hier das neue Design der Schemaakte („shiporder.xsd“):

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of simple elements -->
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
<!-- definition of attributes -->
<xs:attribute name="orderid" type="xs:string"/>
<!-- definition of complex elements -->
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="note" minOccurs="0"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element ref="item" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="orderid" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Verwenden genannter von Types

Die dritte Designmethode definieren Kategorien, oder Arten, die ermöglicht uns, Elementdefinitionen wiederzuverwenden. Dieses wird getan, indem man die simpleTypes und das complexTypes Element nennt, und zeigt dann auf sie durch die Art Attribut des Elements.

Ist hier das dritte Design der Schemaakte („shiporder.xsd“):

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="stringtype">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:simpleType name="inttype">
<xs:restriction base="xs:positiveInteger"/>
</xs:simpleType>
<xs:simpleType name="dectype">
<xs:restriction base="xs:decimal"/>
</xs:simpleType>
<xs:simpleType name="orderidtype">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{6}"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="shiptotype">
<xs:sequence>
<xs:element name="name" type="stringtype"/>
<xs:element name="address" type="stringtype"/>
<xs:element name="city" type="stringtype"/>
<xs:element name="country" type="stringtype"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="itemtype">
<xs:sequence>
<xs:element name="title" type="stringtype"/>
<xs:element name="note" type="stringtype" minOccurs="0"/>
<xs:element name="quantity" type="inttype"/>
<xs:element name="price" type="dectype"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="shipordertype">
<xs:sequence>
<xs:element name="orderperson" type="stringtype"/>
<xs:element name="shipto" type="shiptotype"/>
<xs:element name="item" maxOccurs="unbounded" type="itemtype"/>
</xs:sequence>
<xs:attribute name="orderid" type="orderidtype" use="required"/>
</xs:complexType>
<xs:element name="shiporder" type="shipordertype"/>
</xs:schema>

The restriction element indicate that the datatype is derived from a W3C XML Schema namespace datatype. So, the following fragment mean that the value of the element or attribute must be a string value:

<xs:restriction base="xs:string">

The restriction element is more often used to apply restriction to elements. Look at the following line from the schema above:

<xs:simpleType name="orderidtype">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{6}"/>
</xs:restriction>
</xs:simpleType>

This indicate that the value of the element or attribute must be a string, it must be exactly six characters in a row, and those characters must be a number from 0 to 9.





Previous Next

Keywords: xsd tutorial,xsd xml,xsd dtd,xsd examples,xsd validator,xsd specification,sample xsd,xsd tools,xsd example,xsd editor,xsd syntax,xslt xsd,xsd format,cdata xsd,xml element.


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizes
Oracle Quiz
MySQL Quiz
Operating System Quizes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizes
Testing Quiz
Firewalls Quiz
SAP Module Quizes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizes
Corba Quiz
Networking Quiz
Microsoft Office Quizes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizes
Financial Accounting Quiz
Managerial Accounting Quiz

Privacy Policy
Copyright © 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.