1 / 29

Creating Data Schemas

Creating Data Schemas. Presentation by Chad Borer 2/6/2006. To be covered. Overview of the data schema Starting your Schema the right way The Root Element Parent Elements Child Elements Attributes and Restrictions Ending your Schema the right way.

claus
Télécharger la présentation

Creating Data Schemas

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. Creating Data Schemas Presentation by Chad Borer 2/6/2006

  2. To be covered • Overview of the data schema • Starting your Schema the right way • The Root Element • Parent Elements • Child Elements • Attributes and Restrictions • Ending your Schema the right way

  3. An XML Schema is simply a tree structure defining a relational database As far as functionality goes, it is much like a relational data model In each, one can find descriptions of each object in the database as well as the relations between them. Also, both place restrictions of the data that is entered Overview of a Data Schema

  4. Root Element Parent Element(s) Child Element(s) Attributes MovieDatabase Genre Movie Actor Birthday Overview of a Data Schema

  5. XML Declaration (<?xml version="1.0“…) Namespace declaration (<xsd:schema xmlns:…) Root Element Parent Elements / Child Elements / Attributes Overview of a Data Schema

  6. Always this one line on every data schema: <?xml version="1.0" encoding="UTF-8"?> * Because it is always the same, you can always copy this from an existing schema XML Declaration

  7. The Namespace of a schema consists of the lines of code that come after the XML Declaration and before the actual data structure. They’re the ones you have no idea how to write unless you copy them, and they look like they make absolutely no sense. XML Namespaces

  8. Purposes of Namespaces XML Namespaces • To link the Schema to a standard put out by the W3 Group • To declare each Schema as its own when more than one data Schema is used by an XML file • To force the XML file pointing to the Schema to declare each Namespace in the Schema within itself (confusing, but not necessary to understand right now)

  9. “xsd:schema” – Begins the ‘Schema’ “xmlns:xsd=“…” – Binds this Schema with the W3 standard elementFormDefault=“…” – XML representation attribute XML Namespaces

  10. Entities in General Simple v. Complex Types If an entity only has one value associated with it, it is said to be a simple type, otherwise it is known as a complex type. Not the same as Parent and Child elements

  11. Here is the general structure of a complextype entity in an XML Schema: <xsd:complexType name=“EntityType"> <xsd:sequence> attributes and/or child elements </xsd:sequence> </xsd:complexType> The exception is the Root Element. Entities in General

  12. Don’t confuse the name of the entity and its type. When a child element is included in the description of its parents element, it is given a name and a type associated with it. It is important to distinguish the two apart especially when dealing with stylesheets. You will see this exemplified in the slide after next. Entities in General

  13. The root element is the object under which all the other ones can be grouped. For example, if you wanted to write a Schema for a movie theater, the movie theater itself is the root element. If you wanted to write a Schema for a bunch of cars, you would need to find a root element such as Manufacturer or Dealership The Root Element

  14. <xsd:element name="MovieDatabase"> <xsd:complexType> <xsd:sequence> <xsd:element name="Genre" type="GenreType“ minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> The Root Element

  15. <xsd:element name="MovieDatabase"> There can only be one element defined for a Schema and this is it. The name of the element is contained within the quotation marks. All references in XML files or Stylesheets will use this name The Root Element

  16. <xsd:complexType> <xsd:sequence> Just following the tree structure of the Schema. The Root Element is a complexType because it has child elements. The Root Element

  17. <xsd:element name="Genre" type="GenreType“ minOccurs="1" maxOccurs="unbounded"/> This is the First parent element in the Schema. The element’s name is “Genre” and all references will go to “Genre”. It is of the GenreType type which assumes the GenreType is defined later in the Schema The Root Element

  18. The Root Element </xsd:sequence> </xsd:complexType> </xsd:element> Finishes the tree structure of the Root Element

  19. Parent Elements <xsd:complexType name="GenreType"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="description" type="xsd:string"/> <xsd:element name="movie" type="MovieType" minOccurs="1“ maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType>

  20. Parent Elements <xsd:element name="movie" type="MovieType" minOccurs="1“ maxOccurs="unbounded"/> The child element “MovieType” is why a GenreType is a parent element.

  21. Child Elements <xsd:complexType name="ActorType"> <xsd:sequence> <xsd:element name="lname" type="xsd:string"/> <xsd:element name="fname" type="xsd:string"/> </xsd:sequence> </xsd:complexType>

  22. Attributes and Restrictions An attribute is an entity of a simple type, meaning it had only one value. <xsd:element name="lname" type="xsd:string"/> This particular attribute is of type “string” derived from the W3 group’s standard Schema as indicated by “xsd:string”.

  23. AnyURI Boolean Byte Date DateTime Decimal Double Duration Float gDay gMonth gMonthDay gYear gYearMonth Attributes and Restrictions The W3 standard Schema’s many simple-type attributes • gID • IDREF • IDREFS • Int • Integer • Long • String And more

  24. Restrictions on simpletypes are common and can be very helpful in making sure data integrity stays high. This child element is listed in ActorType and refers to the type “ssnType” which is not included in the W3 standard Schema. Although you cannot see it here, it is based on a “String” <xsd:element name="ssn" type="ssnType"/> Attributes and Restrictions

  25. When placing a restriction on a simple type, a whole new simple type must be created. <xsd:simpleType name="ssnType"> <xsd:restriction base="xsd:string"> <xsd:pattern value="\d{3}-\d{2}-\d{4}"/> </xsd:restriction> </xsd:simpleType> Attributes and Restrictions

  26. Attributes and Restrictions • MinExclusive • MinInclusive • Minlength • Pattern • TotalDigits • whiteSpace • Enumeration • FractionDigits • Length • MaxExclusive • MaxInclusive • MaxLength More about these restrictions if you search Google for xml restriction reference

  27. Ending your Schema • Go back through your Schema and make sure each line of all your elements has been closed with either a “/>” at the end of the line, or a </….> at the end of the coding block. • Last thing to include is </xsd:schema> • You’re done!

  28. Questions? • Overview of the data schema • Starting your Schema the right way • The Root Element • Parent Elements • Child Elements • Attributes and Restrictions • Ending your Schema the right way

  29. Assignment • Draw out a data schema with 4 entities following the tree structure and include attributes for each entity. • Create a well-formed data schema for the model you drew. • Add 3 restrictions to any of the entities created in your schema. Good ones would include enumeration, pattern, and one of the min/max restrictions

More Related