Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session III Chapter 10 – Defining Simple Types

Similar presentations


Presentation on theme: "Session III Chapter 10 – Defining Simple Types"— Presentation transcript:

1 Session III Chapter 10 – Defining Simple Types http://www.profburnett.com

2 Outline XML Simple Element Types Defining a Simple Element Type Using Date and Time Types Using Number Types Predefining an Element Content Deriving Custom Simple Types Deriving Named Custom Types Specifying a Range of Acceptable Values Specifying a Set of Acceptable Values Limiting the Length of an Element Specifying the Pattern for an Element Limiting a Number’s Digits Deriving a List Type Deriving a Union Type 8/1/2014Copyright © Carl M. Burnett2

3 XML Simple Element Types XML simple element contains only text. Cannot contain any other elements or attributes. Most common built-in data types: xs:string xs:decimal xs:integer xs:boolean xs:date xs:time 8/1/2014Copyright © Carl M. Burnett3

4 Defining a Simple Element Type 8/1/2014Copyright © Carl M. Burnett4 1.Type <xs:element to begin the definition. 2.Type name-”label” where label is the name of the XML element that you are defining. 3.Type types=“ 4.Type the following to identify the simple data types: xs:string for string of characters. xs:decimal for decimal number. xs:boolean for true / false. xs:date for a date. xs:time for time. xs:anyURI for a reference to a file. 5.Type > to complete the definition.

5 Using Date and Time Types 8/1/2014Copyright © Carl M. Burnett5 SyntaxFormat xs:gYear YYYY xs:gYearMonth YYYY-MM xs:gMonth --MM xs:gMonthDay --MM—DD xs:gDay --DD SyntaxFormat xs:date YYYY-MM-DD xs:time hh:mm:ss xs:dateTime YYYY:MM:DDThh:mm:ss xs:duration PnYnMnDTnHnMnS Where: P stands for Period T only required for time units Y – Years M – Months D – Days H – Hours M – Minutes S – Seconds

6 Using Number Types 8/1/2014Copyright © Carl M. Burnett6 SyntaxFormat xs:byte A signed 8-bit integer xs:decimal 4.26, -100, or 0 xs:int A signed 32-bit integer xs:integer 542 or -7 xs:positiveInteger 1, 2 xs:negativeInteger 0, -1,-2 xs:nonPositiveInteger 0,-1,-2 xs:nonNegativeInteger 0,1,2 SyntaxFormat xs:float 32-bit floating point numbers xs:short 32-bit integer xs:unsignedLong An unsigned 64-bit integer xs:unsignedInt An unsigned 32-bit integer xs:unsignedShort An unsigned 32-bit integer xs:unsignedByte An unsigned 32-bit integer

7 Predefining an Element Content 8/1/2014Copyright © Carl M. Burnett7 1.Within the element tag type fixed=. 2.Type ”value” where value is what the element must be equal to in order to be considered valid. To Set an Element’s Value To Set an Element’s Default Value 1.Within the element tag type default=. 2.Type ”value” where value is what the element will equal to if empty or omitted.

8 Deriving Custom Simple Types 8/1/2014Copyright © Carl M. Burnett8 1.Identify the name of the XML element that you are using an XML Schema to define. 2.To do so type where label is the name of the XML element. 3.Type to start deriving your custom simple type. 4.Type where foundation is any of the built-in simple types you want to base your custom type. 5.Specify as many restrictions (or facets) as necessary to define your new custom type. 6.Type 7.Type 8.Type to complete the definition of the element.

9 Deriving Named Custom Types 8/1/2014Copyright © Carl M. Burnett9 1.Type <xs:simpleType to start the simple custom type. 2.Type where custom_type_name identifies your new custom simple type. 3.Type where foundation is the simple type upon which you are building your custom type. 4.Specify as many restrictions (or facets) as necessary to define your new custom type. 5.Type 6.Type 7.To use your new custom type using custom_type_name you gave your new custom type.

10 Specifying a Range of Acceptable Values 8/1/2014Copyright © Carl M. Burnett10 To specify the highest possible value Another way to specify the highest possible value 1.Within a custom type definition type <xs:maxInclusive 2.Then, type value="n“, where the element’s content must be less than or equal to n in order to be valid. 3.Finally, type /> to complete the xs:maxInclusive facet. 1. Within a custom type definition type <xs:maxExclusive 2. Then, type value="n", where the element’s content must be less than (but not equal to) n in order to be valid. 3. Finally, type /> to complete the xs:maxExclusive facet.

11 Specifying a Range of Acceptable Values 8/1/2014Copyright © Carl M. Burnett11 To specify the lowest possible value Another way to specify the lowest possible value 1.Within a custom type definition type <xs:mimInclusive 2.Then, type value="n“, where the element’s content must be less than or equal to n in order to be valid. 3.Finally, type /> to complete the xs:minInclusive facet. 1. Within a custom type definition type <xs:minExclusive 2. Then, type value="n", where the element’s content must be less than (but not equal to) n in order to be valid. 3. Finally, type /> to complete the xs:minExclusive facet.

12 Specifying a Set of Acceptable Values 8/1/2014Copyright © Carl M. Burnett12 1. Within a custom type definition, type <xs:enumeration. 2. Then, type value="choice", to identify one acceptable choice for the content of the element or attribute. 3. Finally, type /> to complete the xs:enumeration element. 4. Repeat Steps 1–3 for each addition

13 Limiting the Length of an Element 8/1/2014Copyright © Carl M. Burnett13 To specify the exact length of an element Within a custom type definition type, where g is the number of characters that the element must have. To specify the Minimum length of an element Within a custom type definition type, where n is the minimum length of characters that the element must have. To specify the Maximum length of an element Within a custom type definition type, where x is the maximum length of characters that the element must have.

14 Specifying the Pattern for an Element 8/1/2014Copyright © Carl M. Burnett14 1.Within a custom type definition type <xs:pattern. 2.Then, type value="regex", where regex is the regular 3.expression that the XML element’s content must match. Regular expressions are made up of letters, numbers, and special symbols; in the order which those letters, numbers, and symbols should appear in the content. Symbols include:. (a period) for any character at all. \d for any digit; \D for any non-digit. \s for any white space (including space, tab, newline, and return); \S for any character that is not white space. x* to have zero or more x’s; (xy)* to have zero or more xy’s. x? to have zero or one x; (xy)? to have zero or one xy. x+ to have one or more x’s; (xy)+ to have one or more xy’s. [abc] to include one of a group of values (a, b, or c). [0–9] to include the range of values from 0 to 9.

15 Specifying the Pattern for an Element 8/1/2014Copyright © Carl M. Burnett15 1.Within a custom type definition type <xs:pattern. 2.Then, type value="regex", where regex is the regular expression that the XML element’s content must match. Regular expressions are made up of letters, numbers, and special symbols; in the order which those letters, numbers, and symbols should appear in the content. 3. Finally, type /> to complete the xs:pattern element. Symbols include:. (a period) for any character at all. \d for any digit; \D for any non-digit. \s for any white space (including space, tab, newline, and return); \S for any character that is not white space. x* to have zero or more x’s; (xy)* to have zero or more xy’s. x? to have zero or one x; (xy)? to have zero or one xy. x+ to have one or more x’s; (xy)+ to have one or more xy’s. [abc] to include one of a group of values (a, b, or c). [0–9] to include the range of values from 0 to 9. this | that to have this or that in the content. Separate additional choices with additional vertical bars. x{5} to have exactly 5 x’s (in a row). x{5,} to have at least 5 x’s (in a row). x{5,8} to have at least 5 and at most 8 x’s (in a row). (xyz){2} to have exactly two xyz’s (in a row). Note: Parentheses control what the curly brackets and other modifiers, such as ?, +, and *, affect.

16 Specifying the Pattern for an Element 8/1/2014Copyright © Carl M. Burnett16

17 Limiting a Number’s Digits 8/1/2014Copyright © Carl M. Burnett17 To specify the total number of digits in a number To specify the number of digits after the decimal point 1. Within a custom type definition type <xs:totalDigits. 2. Then, type value="n", where n is the maximum number of digits that can appear in the number. 3. Finally, type /> to complete the xs:totalDigits facet. 1. Within a custom type definition type <xs:fractionDigits. 2. Then, type value="n", where n is the maximum number of digits that can appear after the decimal in the number. 3. Finally, type /> to complete the xs:fractionDigits facet.

18 Deriving a List Type 8/1/2014Copyright © Carl M. Burnett18 1.First, identify the name of the XML element that you are using XML Schema to define. 2.Type, where label is the name of the XML element. 3.Type to start deriving your custom simple type. 4.Type, where list_element is the simple type (built in or custom) that defines each individual unit in your list. 5.Type to complete your new custom simple type. 6.Type to complete the definition of the element.

19 Deriving a Union Type 8/1/2014Copyright © Carl M. Burnett19 1.First, identify the name of the XML element that you are using XML Schema to define. 2.Type, where label is the name of the XML element. 3.Type to start your custom simple type. 4.Type, where union_elements is a white-space-separated group of simple types (built-in or custom) that define the valid simple types for this element. 5.Type to complete your new custom simple type. 6.Type to complete the definition of the element.

20 Review XML Simple Element Types Defining a Simple Element Type Using Date and Time Types Using Number Types Predefining an Element Content Deriving Custom Simple Types Deriving Named Custom Types Specifying a Range of Acceptable Values Specifying a Set of Acceptable Values Limiting the Length of an Element Specifying the Pattern for an Element Limiting a Number’s Digits Deriving a List Type Deriving a Union Type 8/1/2014Copyright © Carl M. Burnett20 Next: Chapter 11 – Complex Types


Download ppt "Session III Chapter 10 – Defining Simple Types"

Similar presentations


Ads by Google