Schema
| Definition: |
| Describe and validate data |
| communicate structure to applications and people |
| constrain element content |
| provide default attribute values |
| XML based syntax -- you can use all the XML tools in schemas: DOM, SAX,XSLT, and transform or contruct shemas on the fly using DOM orXSLT |
| Support NAMESPACES and multiple schema references for each XML document |
| derive your own datatypes |
| Allow inheritance |
| data-types (like string, byte, etc) |
| import and export data from a database |
| escape characters |
Unicode specs --Character References |
|
| save as | *.xsd file | |
| linking to page: | xml links | xpath |
| if you do not have a default namespace: | <?xml version="1.0" ?> <schema> <element name="b" type="string" /> -- this is the bold tag for html and can be declared </schema> |
|
| Namespaces | Another place to simultaneously define your tags XML reference to tell our xml where to look for it's definitions: |
|
| primary components | ||
| typecasting | your elements and attributes can be identifies
as many basic programming types using the "type" built-in attribute A list of the actual types |
|
| complex typecasting | set up your own objects | |
| element declarations | setting up your basic data | |
| attribute declarations | define and control your data | |
| secondary components | extend complex types | |
| Helper components | cannot be named or independently accessed, xsd built-in attributes to use in your schema | |
| Attributes | |||
| Built-In Attributes | Defines and controls the elements and attributes in the Schema | ||
| Use with Your attributes AND elements | |||
| Can use built in attributes in the
schema (not in the XML) Example <element name="price" type="decimal" /> |
|||
| Your Own Attributes | Use to define your data in the XML | ||
| Use with Your elements | |||
| Your own made-up attributes must be declared in a complex type | |||
| List at the END of your complex type | |||
| Helper Components | |
| Example |
In XML In Schema |
| name | any name you give it |
| Example <element name="myName"> |
|
| type | see typecasting, above |
| Example <element name="myName" type="xsl:string" /> |
|
| minOccurs/maxOccurs | define number of times an element can occur |
| Example <element name="myName" minOccurs="1" maxOccurs="1" /> <element name="myName" minOccurs="0" maxOccurs="1" /> <element name="myName" minOccurs="1" maxOccurs="unbounded" /> <element name="myName" minOccurs="1" maxOccurs="unbounded" /> |
|
| value | sets the default value for an element or attribute |
| Example <element name="myName" value="inStock"> <attribute name="myName" value="inWarehouse" / > </element> |
|
| use | required Example <element name="myName" use="xsd:required" / > |
| fixed Example <element name="myName" use="xsd:fixed" /> |
|
| implied Example <element name="myName" use="xsd:implied" / > |
|
| prohibited Example <element name="myName" use="xsd:prohibited" fixed="weekSpecial" /> (won't use this attribute on the XML) |
|
| fixed | sets the value of an attribute or an element, and can't change it in your XML, or this node could be empty in your XML data |
| default | sets the default value of an attribute or element, but you can change it in XML |
| nillable | either "true" or "false", means that the tag has a null value, explained in identity constraints |
| restriction | Negates the type you specify |
| memberTypes | used with a union |
| itemType | used with list |
| group | used in elements to group elements together |
| complexContent | Used in |
| All | used in unnamed complex types, specifies that
those elements only appear in this group has to be at the top level of that content model used in a named model group to restrict those elements to only that group |
| Choice | used in unnamed complex types,
specifies the choices of elements used in a named model group to specifiy the choices of elements |
| Sequence | used in unnamed complex types,
specifies the order those elements are allowed to appear used in a named model group to specify the order those elements are allowed to appear |
| Attribute Group | groups a bunch of attributes together |
| system | identifies what viewer you would use in a notation |
| public | allows network access to documents |
| extension | |
| base | |
| key | sets up primary key in an xml data , see identity constraints |
| keyref | foreign key in your xml data , see identity constraints |
| unique | allows you to set up unique keys for relational databases, see identity constraints |
| xpath | retrieves the range of elements or attributes needed |
| selector | selects the xml tag that your are going to need |
| field | identifies the child node for our query |
| annotation | sets up documentation and appInfo for the schema, see identity constraints |
| documentation | sets up comments to describe the application being accessed, see identity constraints |
| appInfo | a processing instruction -- passes information to a processing application, see identity constraints |
| User-Derived Types | you set these types up yourself, limited by the base type you set it up from |
| enumeration | this is a user-derived type, allows you to choose from a set list of allowable values |
| pattern | this is a user-derived type, allows you to look for an allowable pattern in the value of the attribute or element |
| whiteSpace | this is a user-derived type, allows you to set up the whitespace |
| minInclusive, maxInclusive | this is a user-derived type, allows you to set up a range of values allowed |
| minExclusive, maxExclusive | this is a user-derived type, allows you to set up a range of values allowed |
| totalDigits, fractionDigits | this is a user-derived type, allows you to limit the total number of digits or decimals allowed in your number |
| Elements | |||
| Simple Elements | Contains none of your own attributes or child elements | ||
| In XML the element can be empty or have text | |||
| In XML, the empty example: <element name="myelement" /> |
|||
| In XML, with text example: <element name="myelement">Here is my text with & (properly escaped illegal characters)</element> |
|||
| Name is a built-in attribute, you can
add all the built-in attributes listed These define and control many parameters of your element |
|||
| Complex Elements | Can use child elements and attributes that you define | ||
| Create your own objects | |||
| Control the order and parameters of every attribute and element | |||
| Simple Element | |||||
| element | Contains no child elements | ||||
| define number of times an element can occur | <xsd:element name="dateReceived"
type="xsd:date" minOccurs="0" maxOccurs="1"
/> |
[none] | zero or one time occuring | ||
| minOccurs="1" maxOccurs="1" | ? | one and only once | |||
| minOccurs="0" maxOccurs="unbounded" | * | zero or more | |||
| minOccurs="1" maxOccurs="unbounded" | + | ||||
| Attributes | Built-in attributes describe and define your element Can use built in attributes in the schema (not in the XML) |
||||
| Derived from Simple Type | enumeration | can be any number of occurances, including 0 only has that element, no text inside of it (elementOnly) |
Example <element name="price" type="decimal"> <simpleType base="string"> <enumeration value="cost" /> <enumeration value="sale" /> <enumeration value="retail" /> <enumeration value="starting" /> </simpleType> </element> |
||
| list |
<listFromMyList>1 5 6 19</listFromMyList> In schema <xsd:simpleType name="listFromMyList"> (new object, new name) <xsd:list itemType= "myList" /> </xsd:simpleType> |
||||
| union |
<listFromColor>red blue yellow green</listFromColor> <listFromSize>s m l xl</listFromSize> In schema <xsd:simpleType name="listFromColor"> <xsd:list itemType= "Color" /> </xsd:simpleType> <xsd:simpleType name="listFromSize"> <xsd:list itemType= "Size" /> </xsd:simpleType> With union <xsd:simpleType name="choicesUnion"> <xsd:list memberTypes= "Color Size" /> </xsd:simpleType> In XML, now <choicesUnion /> |
||||
| Complex Types | ||||
| Attribute to a complex type | complex types hold attributes. - must declare as a complexType, or no declaration for simpleType - at all | |||
|
<xsd:element name="invoice"> In XML: |
||||
|
If we wanted to use this attribute many times: declare this on it's own line <attribute name="paid" use="optional" default="false" type="NMTOKEN" />
Later, refer to it in another element In XML: |
||||
| mixed elements | define whether items appear | |||
| <element name="advertisement"
content="mixed"> <element name="ad_sentence" content="mixed"> <element ref="b" minOccurs="0" /> </element> </element> In XML: |
||||
| ref | previously defined elements, used within another element | |||
|
<element name="short_desc" type="string"/> <element name="suite" content="elementOnly"> In XML: |
||||
| content | elementOnly -- no text | |||
| mixed -- contains elements and/or text, and/or attributes | ||||
| Unnamed complex Type sequence |
define the order items appear | |||
| <xsd:complexType name="address"> <xsd:sequence> <xsd:element name="street1" /> <xsd:element name="street2" /> <xsd:element name="city" /> <xsd:element name="state" /> <xsd:element name="zip" /> </xsd:sequence> </xsd:complexType> <xsd:element name="mailingAddress" type="address" /> <xsd:element name="billingAddress" type="address" /> In XML: <mailingAddress> <street1>xxx</street1> <street2>xxx</street2> <city>xxx</city> <state>xxx</state> <zip>xxx</zip> </mailingAddress> |
||||
| Unnamed complex Type choice |
Cannot use this type by itself in our XML - just
the choices inside the type Does not have the "element" identifier as the root node |
|||
|
<xsd:complexType name="products" content="elementOnly"
>(no text, just elements here) In XML: |
||||
| Named complex type | Allows us to use this complex type by itself in our xml, in
addition to using it within another complex type Has the "element" identifier as the root node |
|||
|
<xsd:element name="address"> And, in XML: |
||||
| Complex Type Example: |
<?xml version ="1.0" ?> <xsd:element name="contactDetails">
<xsd:complexType> <xsd:sequence> <xsd:element name="firstName" /> <xsd:element name="middleInitial" minOccurs="1" maxOccurs="unbounded" /> <xsd:element name="lastName" /> </xsd:sequence> </xsd:complexType> <xsd:element name="mailingAddress" type="address" /> <xsd:element name="billingAddress" type="address" /> </xsd:element> </xsd:complexType> </xsd:element> <xsd:complexType name="address"> In XML: |
|||
| Extend a complex typeNOTCHECKED |
<xsd:element name="addressTime"> And, in XML (of the complex type above with the extension): |
|||
| Empty | This type can ONLY carry attributes, no child elements or text | |||
| <xsd:element name="product"> <xsd:complexType> <xsd:complexContent> <xsd:restriction base="xsd:AnyType" /> <xsd:attribute name="productID" use="required" type="xsd:id" /> <xsd:attribute name="name" use="required" type="xsd:string" /> </xsd:restriction> </xsd:complexContent> </xsd:complexType> </xsd:element> |
||||
| ElementOnly | only child elements are included in your element, no text | |||
| <element name="item"
content="elementOnly"> <element ref="product_desc"/> <element ref="price" minOccurs="0" maxOccurs="unbounded"/> </element> |
||||
| mixedType | contains text and child elements in the XML | |||
|
Easy example <element name="advertisement" content="mixed"> |
||||
|
In Schema <xsd:element name="autoResponse"> In XML |
||||
| Typecasting Example <element name="myName" type="xsl:string" /> |
||
| string | basic problem characters need to be escaped see: string literals or Unicode | |
| normalized strings | do not contain carriage return, tabs, or linefeed (i.e. these are also escaped see: string literals or Unicode) | |
| numeric types | boolean | true, false, 1, 0 |
| byte | -127 to 127 | |
| int | -2.5 0E7 to +2.5 OE7 | |
| short | int which is derived from long, -3.5 0E7 to +3.5 OE7 | |
| number | 18 decimal places | |
| long | -9.2 0E19 to +9.2 0E19 | |
| nonNegative Integer | includes zero | |
| negativeInteger | not including zero | |
| positiveInteger | an integer of 1 or higher | |
| decimal | ||
| float | -1E4. 4.5E-2, NaN (means not a number) (32 bit floating point type) | |
| double | (64 bit floating point type) | |
| unsignedShort/unsignedLong | 0 and 1.8 0E20 (or 0E7 for short) | |
| unsignedByte | 0 and 255 | |
| unsignedInt | 0 and 4.2 0E10 | |
| hexBinary | arbitrary hex-encoded binary data | |
| base64Binary | any Base-64 encoded binary data | |
| time-related types | timeInstant | |
| timeperiod | ||
| century | ||
| recurringDate | ||
| recurringDay | ||
| duration | PnYnMnDTnHnMnS | |
| P1Y0M1DT20:25:30 Means: P must be present nY number of years (1 year) nM number of months (0 months) nD number of days (1 day) T is the time separator 20 hours, 25 minutes, 30 seconds |
||
| PnYnMnDTnHnMnS | ||
| PnYnMnDTnHnMnS | ||
| recurringDuration | ||
| date | YYYY-MM-DD, cannot be split up | |
| time | HH:MM:SS | |
| datetime | CCYY-MM-DD-Thh:mm:ss T is the time separator, then no space to hours (hh) |
|
| gYearMonth | CCYY-MM | |
| gYear | CCYY | |
| gMonthDay | MM-DD | |
| gDay | DD | |
| gMonth | MM | |
| tokenized types | id | |
| idref | ||
| idrefs | ||
| entity | derived from ncName | |
| entities | ||
| nmtoken | nmtoken can only use certain defined types | |
| nmtokens | same nmtokens as DTD Example: small medium large (just a space between) <element name="inventory" type="integer"> <attribute name="location" type="NMTOKEN" use="default" value="warehouse" /> </element> |
|
| notation | should not appear directly in the schema, only for deriving other data-types by specifying a value for enumeration which can be used in the schema | |
| anyURI | value can be absolute or relative, may have a fragment identifier
(so it could be a URI reference) URI information |
|
| qName | any XML namespace Example: xsd:element |
|
| token | tokenized strings, it is a normalized string, plus, no leading or trailing spaces, or more than two spaces in a row | |
| language | xml:lang definitions | |
| name | any XML name Example: <element name="address"> |
|
| ncName | a qName without the prefix and colon ("http:") | |
| Content Types | simpleType | create new types from this type (see 3 examples, below) |
| contains NO other elements or attributes | ||
| complexType | create your own type | |
| anyType | this is the default type | |
| elementOnly | only child elements are included in your element, no text | |
| Empty | This type can ONLY carry attributes, no child elements or text | |
| mixedType | allows elements to include text and child elements It is a complex type |
|
| Secondary Components | ||
| Create a group element | must be declared as a top-level schema component -- a child of the schema element | |
| attribute groups | groups attributes together | |
|
Example: Refer to our group: Now, our attributeGroup In XML: |
||
| model group definitions | groups elements together | |
|
can consist of
|
||
|
Example: <xsd:group name="mealOptions"> Not a named element,
just include the choices, not "mealOptions" in XML Now, to refer to our group: In XML: ????????? |
||
| All | only be used within that group | |
|
Example: <xsd:group name="creditCardInfo"> |
||
| identity constraints | they specify a relationship between any attribute,
element and it's content or value, even from a combination of element and
attribute content. And it allows you to specify the scope where the constraints
apply All these elements and attributes that you set up are going to be required nodes in you schema, if their corresponding element is used |
|
| unique | allows you to say that the value of the attribute or content of an element should be unique | |
| <xsd:unique name="uniqueID"> <xsd:selector xpath="tc:product/" />selector sets up the xml tag that we need to look at for our query <xsd:field xpath="tc:@productID" />selector sets up the node that we need to designate for a unique value <xsd:selector xpath="tc:order/" /> <xsd:field xpath="tc:@productID" />here we set up our next unique value <xsd:selector xpath="tc:customers/" />now, we are getting two ids from a complex element <xsd:field xpath="tc:tradeCustomer/@custID" /> <xsd:selector xpath="tc:publicCustomer/@custID" /> </xsd:unique> |
||
| key | primary key, allows you to set up the realtionship between any attribute and any element's content or value | |
| <xsd:key name="customerID" > <xsd:selector xpath="tc:salesData/" /> <xsd:field xpath="tc:customer/@custID" /> </xsd:key> <xsd:keyref name="item" refer="customerID" /> <xsd:selector xpath="tc:salesData/" /> <xsd:field xpath="tc:invoice/@invoiceID" /> </xsd:keyref> |
||
| keyref | foreign key , reference the key that you already set up | |
| <xsd:element name="cardType" /> <xsd:element name="cardHolderName" /> <xsd:element name="cardNumber" /> <xsd:element name="cardExpireDate" /> </xsd:all> </xsd:group> |
||
| nillable |
|
|
|
In Schema In XML |
||
| annotation | Sets up the application used. | |
|
<xsd:annotation> |
||
|
<xsd:annotation> |
||
| User-Derived Types notation declarations | Are only used to associate a name with the application used to view that type of document | |
|
<xsd:notation name="jpeg" public="image/jpeg"
system="jviewer.exe" /> the public identifier tells us where the picture is, system tells us what viewer to use <xsd:element name="image"> |
||
| Create our own derived types from the built-in types given | ||
| Value spaces | do not include the unicode character set | |
| include abstract properties like equality, order, bounds, cardinality an numeric/non-numeric properties | ||
| Lexical Spaces | include the Unicode character set | |
| length | limits the number of units of length, characters
(string type), octets (binary type), or list items Example:
<xsd:restriction base="xsd:int"> <xsd:length value="3" /> </xsd:restriction> </simpleType> |
|
| minLength | ||
| maxLength | limited by the size of the parent element (so a type derived from a byte cannot have a maxLength of 4 or higher | |
| pattern | limits the literals comprising the value of a facet
to a pattern defined by a regular expression Example:
<xsd:restriction base="xsd:int"> <xsd:minLength value="3" /> <xsd:maxLength value="3" /> <xsd:pattern value="[1][0-9][0-9]" /> </xsd:restriction> </simpleType> |
|
| enumeration | limits the facet to a specific value, if the value
isn't specified in the schema, it isn't valid Example:
<xsd:restriction base="xsd:string"> <xsd:enumeration value="accounts" /> <xsd:enumeration value="sales" /> <xsd:enumeration value="warehouse" /> <xsd:enumeration value="web" /> <xsd:enumeration value="marketing" /> <xsd:enumeration value="customer support" /> </xsd:restriction> </simpleType> |
|
| maxInclusive | specific inclusive upper bound | |
| maxExclusive | (the value is NOT included in the boundary) | |
| minInclusive | specific inclusive lower bound | |
| minExclusive | Example
|
|
| whiteSpace | says whether whitespace is allowed.
|
|
| totalDigits | specific max number of decimal digits (non-negative integer) | |
| fractionDigits | specific max number of decimal digits in the fractional part | |