Schemas 2 - Restricting Values
Upcoming SlideShare
Loading in...5
×
 

Schemas 2 - Restricting Values

on

  • 515 views

 

Statistics

Views

Total Views
515
Views on SlideShare
407
Embed Views
108

Actions

Likes
0
Downloads
11
Comments
0

1 Embed 108

http://angel.spscc.edu 108

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Schemas 2 - Restricting Values Schemas 2 - Restricting Values Presentation Transcript

  • CIS-189 XML
  •  Qualification refers to whether a value (element, attribute) must be qualified by a its namespace ◦ When an element (or attribute) doesn’t have a namespace declaration it’s unqualified ◦ Determines how name is used in data (instance) document A schema has the attributes elementFormDefault and attributeFormDefault ◦ Set to qualified or unqualified ◦ By setting to qualified, must include a namespace when use attributes or elements
  • <schema attiributeFormDefault=“unqualified”elementFormDefault=“unqualified”> Element and attributes can be specified individually as qualified (or not) <element form=“unqualified”> <attribute form=“qualified”>
  •  Have several different ways to specify how elements fit together Sequence: specifies that elements must be in order, and there’s variability in when and how many times a child element occurs All: elements may appear (or not), and in any order Choice: one of several child elements may appear Group: a set of elements may be referenced by name
  •  Allows elements to appear in any order or not at all Rules governing use 1. Must be only content model declaration of a <complexType> definition  For example, can’t follow with <sequence> 2. Can only have element declarations as children 3. The children of the <all> element may appear once – or not at all
  • <element name=“name”> <complexType> <all> <element name=“first” type=“xs:string” /> <element name=“middle” type=“xs:string” /> <element name=“last” type=“xs:string” /> </all> </complextType></element>
  •  Similar in syntax to sequence Only one member of list can appear in the document Allow a middle initial or a middle name<choice> <element name=“middleInitial” type=“xs:string” /> <element name=“middleName type=“xs:string” /></choice>Note: Best case would restrict Middle Initial to onecharacter with a simple type.
  •  A group allows you to tie elements together, and then reference then with a single nameDefinition:<group name=“nameFields”> <element name=“first” type=“xs:string” /> <element name=“middle” type=“xs:string” /> <element name=“last” type=“xs:string” /></group>Use:<element name=“name”> <complexType> <group ref=“nameFields” /> </complexType></element>
  •  Can create a group of attributes similar to element groups Allows re-use of common members without multiple definitions ◦ Attribute groups cannot be recursive (refer to themselves
  •  Create limits on acceptable values as a simple type A facet is a single property or trait of a simple type Twelve facets can be applied to limit acceptable values
  •  minExclusive: smallest value, excluding what’s specified minInclusive: smallest value, including what’s specified maxExclusive: largest value, excluding what’s specified maxInclusive: largest value, including what’s specified totalDigits: total number of digits of a numeric type
  •  fractionDigits: number of decimal places length: number of items in a list or characters in a string minLength: minimum number of list items or characters maxLength: maximum number of list items or characters enumeration: specify member of a list whitespace: how whitespace should be treated pattern: restrict string types by pattern
  • Specifying a positive integer<xs:simpleType name="creditHours"> <xs:restriction base="xs:integer"> <xs:minInclusive value="0" /> </xs:restriction></xs:simpleType>
  • Specifying a list:<xs:simpleType name="cisDepartments"> <xs:restriction base="xs:string"> <xs:enumeration value="CIS" /> <xs:enumeration value="CNA" /> <xs:enumeration value="CS" /> </xs:restriction></xs:simpleType>
  •  Specify a 3 digit value<xs:simpleType name="courseNumbering"> <xs:restriction base="xs:string"> <xs:pattern value="b[0-9]{3}b" /> </xs:restriction></xs:simpleType>
  • <?xml version="1.0" encoding="utf-8"?><xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema”> <xs:element name="course"> <xs:complexType> <xs:sequence> <xs:element name="department" type="cisDepartments" /> <xs:element name="number" type="courseNumbering" /> <xs:element name="title" type="xs:string" /> <xs:element name="credits" type="creditHours" /> </xs:sequence> </xs:complexType> </xs:element>
  • <xs:simpleType name="creditHours"> <xs:restriction base="xs:integer"> <xs:minInclusive value="0" /> </xs:restriction></xs:simpleType><xs:simpleType name="cisDepartments"> <xs:restriction base="xs:string"> <xs:enumeration value="CIS" /> <xs:enumeration value="CNA" /> <xs:enumeration value="CS" /> </xs:restriction></xs:simpleType><xs:simpleType name="courseNumbering"> <xs:restriction base="xs:string"> <xs:pattern value="b[0-9]{3}b" /> </xs:restriction></xs:simpleType></xs:schema>
  •  A list allows an element or attribute to store multiple values ◦ Uses enumerated values ◦ Values are separated by whitespace, so whitespace cannot be part of the content ◦ Can be built-in XML or a defined simpleType data type
  • Define<simpleType name=“Degrees”> different <restriction base=“string”> values <enumeration value=“AA” /> <enumeration value=“AS” /> <enumeration value=“AAS” /> </restriction></simpleType> Define<simpleType name=“DegreesList”> data type <list itemType=“Degrees”/> using</simpleType> values<element name=“degreesEarned” type=“DegreesList” /> Define element storing different values
  •  <union> allows the combination of two data type for an element or attribute If have a possiblePoints element, expected value would be an integer; <union> would allow a string entry to note a “Missing” value Separate data types with whitespace<simpleType name=“CreditValue”><union memberTypes=“xs:integer xs:string /></simpleType
  • <xs:simpleType name="zipCode"> <xs:union> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[0-9]{5}" /> </xs:restriction> </xs:simpleType> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[0-9]{5}-[0-9]{4}" /> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType>