html5-img
1 / 11

XML Schema Definition Language (XSD)

XML Schema Definition Language (XSD). Презентацию подготовил Габдрахманов Рамиль, гр.950б. Схемы XSD решают следующие задачи. Перечисление элементов в документе XML и проверка наличия в документе объявленных элементов.

stu
Télécharger la présentation

XML Schema Definition Language (XSD)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Schema Definition Language (XSD) Презентацию подготовил Габдрахманов Рамиль, гр.950б

  2. Схемы XSD решают следующие задачи • Перечисление элементов в документе XML и проверка наличия в документе объявленных элементов. • Объявление и определение атрибутов, модифицирующих элементы документа. • Определение родительско-дочерних отношений между элементами. • Определение состояний и моделей содержания для элементов и атрибутов. • Задание типов данных. • Установка значений по умолчанию. • Возможность расширения. • Поддержка использования пространств имен.

  3. Примеры элементов простого и сложного типов Простой тип: <message>Remember to buy milk on the way home from work</message> <delivery>email</delivery> Сложный тип: <message number="10" date="2001-07-29" from="Kathy Shepherd"> Remember to buy milk on the way home from work <receipt> <complete/> </receipt> </message>

  4. Пространства имен XSD Листинг 1. Схема XSD для проверки документа message01.xsd 1: <?xml version="1.0"?> 2: <xsd:schema 3: xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" 4 : elementFormDefault="qualified"> 5: <xsd:element name="note" type="xsd:string"/> 6: </xsd:schema> Листинг 2. Экземпляр XML, в котором показано пространство инен XSD, message01.xml. 1: <?xml version="1.0"?> 2: <note 3: xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" 4 : xsi:noNamespaceSchemaLocation="message01.xsd"> 5: Remember to buy milk on the way home from work 6: </note>

  5. Простой тип string normalizedString byte unsignedByte base64Binary hexBinary integer positivelnteger negativelnteger nonNegativelnteger nonPositivelnteger decimal float double boolean time dateTime duration date gMonth gYear gYearMonth gDay gMonthDay Name Описание Буквенно-цифровая строка Строка без пробелов -1126 0,126 GpM7 OFB7 -126789, -1, 0, 1, 126789 1,126789 -1267879,-1 О, 1, 126789 -1267879,-1,0 -1.23, 0, 123.4, 1000.0 -INF, -1E4, -0, 0, 12.78E-2, 12, INF, Nan -INF, -1E4, -0, 0, 12.78E-2, 12, INF, Nan True, false, 1, 0 13:20:00.000, 13:20:00.000-5:00 1999-05-31T1313:20:00.000-5:00 P1Y2M3DT10H30M12.S3 1999-05-31 -05- 1999 1999-02 —31 -05-31 shipTo Простые типы данных, используемые всхемах XSD

  6. Примеры с элементами сложных типов Листинг З. Документ XML, в котором содержится элемент с вложенным элементом, message02.xml 1: <?xml version="l.0"?> 2: <note 3: xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" 4: xsi:noNamespaceSchemaLocation="message02.xsd"> 5: <message>Remember to buy milk on the way home from work</message> 6: </note> Листинг 4. Схема XSD, содержащая элемент xsd:ComplexType, message02. xsd 1: <:?xml version="l. 0"?> 2: <xsd:schema 3: xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"> 4 : <xsd:element name="message" type="xsd:string"/> 5: <xsd:element name="note"> 6: <xsd:complexType> 7: <xsd:sequence> 8 : <xsd:element ref="message"/> 9: </xsd:sequence> 10: </xsd:complexType> 11: </xsd:element> 12: </xsd:scheraa>

  7. Ограничения вхождений в схемах XSD Листинг 5. Экземпляр XML со сложным вложением message03. xml 1: <?xml version-"l. 0"?> 2: <note 3: xmlns:xsi="http://www.w3.org/2 000/10/XMLSchema-instance" 4: xsi:noNamespaceSchemaLocation="message03.xsd"> 5: <notes> 6: <number/> 7: <message>Remember to buy milk on the way home from work</message> 8: <message>Skim Milk is preferred</message> 9: </notes> 10: <notes> 11: <number/> 12: <message>Pick up shirts from the cleaners</message> 13: <message>Got to the bank</message> 14: <message>Cut the lawn</message> 15: </notes> 16: </note>

  8. Ограничения вхождений в схемах XSD Листинг 6. Атрибуты minOccur и maxOccur в схеме XSD — messageO3. xsd 1:<?xml version="l.0"?> 2: <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"> 3: <xsd:element name="message" type="xsd:string"/> 4 : <xsd:element name="number"/> 5 : <xsd:element name="note"> 6: <xsd:complexType> 7 : <xsd:sequence> 8: <xsd:element name="notes" minOccurs="0" maxOccurs="2"/> 9: </xsd:sequence> 10: </xsd:complexType> 11: </xsd:element> 12: <xsd:complexType name="notesType"> 13: <xsd:sequence> 14 : <xsd:element ref="number"/> 15: <xsd:element ref="message" maxOccurs="unbounded"/> 16: </xsd:sequence> 17: </xsd:complexType> 18: </xsd:schema>

  9. Атрибуты в схемах XSD Листинг 7. Использование нескольких атрибутов message04.xml 1:<?xml version="l.0"?> 2: <note 3: xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" 4: xsi:noNamespaceSchemaLocation="message04.xsd"> 5: <message number="10" date="2001-07-29" from="Kathy Shepherd"> 6: Remember to buy milk on the way home from work 7: </message> 8: </note>

  10. Атрибуты в схемах XSD Листинг 8. Схема XSD для проверки экземпляра XML с несколькими атрибутами message04.xsd. • <?xml version="l.0"?> • <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"> • <xsd:complexType name="messageType"> • <xsd:simpleContent> • <xsd:restriction base="xsd:string"> • <xsd:attribute name="number" type="xsd:integer" use="required"/> • <xsd:attribute name="date" type="xsd:date" use="required"/> • <xsd: attribute name=“from" type="xsd : string" use="required"/> • </xsd:restriction> • </xsd:simpleContent> • </xsd:complexType> • <xsd:element name="note"> • <xsd:complexType> • <xsd:sequence> • <xsd:element name="message" type="messageType"/> • </xsd:sequence> • </xsd:complexType> • </xsd:element> • </xsd:schema>

  11. The End.

More Related