XML Schemas 1 Useful Links Schema tutorial links: http://www.w3schools.com/schema/default.asp http://www.xfront.com/ http://www.w3.org/TR/xmlschema-0/ 2 Why Schemas Enhanced datatypes 44+ versus 10
Can create your own datatypes Example: "This is a new type based on the string type and elements of this type must follow this pattern: ddddddd, where 'd' represents a digit". Written in the same syntax as instance documents: less syntax to remember Can extend or restrict a type (derive new type definitions on the basis of old ones) Can express sets, i.e., can define the child elements to occur in any order Can specify element content as being unique (keys on content) and uniqueness within a region Can define multiple elements with the same name but different content Can define substitutable elements - e.g., the "Book" element is substitutable for the "Publication" element. 3 Schemas and DTDs
One difference between XML Schemas and DTDs is that the XML Schema vocabulary is associated with a name (namespace). Likewise, the new vocabulary that you define must be associated with a name (namespace). With DTDs neither set of vocabulary is associated with a name (namespace). 4 Some XML Parsers with Schema Support A comparison of some XML parsers: http://webreference.com/xml/column22/2.html 5 Example BookCatalog.dtd
6 An Example Of A Schema Definition BookCatalog.xsd
7 BookCatalog.xml Billions Of StarsSusan Boggs19831-5555-555-2Anderson-WellsAdventures Of Freddie the Frog
John Smith19770-444-4444-4Kidder Publishing Co. 8 Schema namespace Schema element: All XML schemas have schema as the root element. XML Schema namespace: The elements and datatypes that are used to construct schemas, like, schema, element, complexType, sequence and string come from the http:///XMLSchema namespace 9 Using namespaces Example plants.xsd
10 Example plants.xml Daisyperennial 11 Example BookCatalog.xsd
12 BookCatalog.xml Billions Of StarsSusan Boggs19831-5555-555-2Anderson-Wells
Adventures Of Freddie the FrogJohn Smith19770-444-4444-4Kidder Publishing Co. 13 Simple vs Complex Types
A schema document can be divided into content types: Simple and complex types. Simple types: can contain only text. There are several simple builtin types String, Boolean, Float, Double, ID, IDREF, Entity etc. Derived data types: The built-in data types can be customized to control the content. Complex types: can contain elements that can contain other elements or attributes. Local vs global declarations: Schema components, elements, attributes, named simple and complex types, declared under xsd:schema element are considered globally declared. A global declaration has to be explicitly referenced. New elements can be declared within the context of a complex type, in which case they are considered locally declared. 14 Simple Types: exampleA.xsd
15 exampleA.xml Billions Of Stars2000-01-021983true
16 Deriving From Simple Types A new custom type can be derived a simple type. Example: -- refers to a simple type Patterns are specified using regular expressions (supports regular expressions from perl) 17
Example Example3.xsd and Example3.xml
Billions Of Stars 2-12345-678-9 18 Giving a choice of acceptable values base="xsd:string"> value="autobiography"/> value="non-fiction"/>
19 Defining Complex Types Elements that can contain other elements or attributes. There are four kinds of elements of complex type: Elements that contain other elements and attributes, but no text. Elements that are empty possibly contain attributes but no other elements or text.
Elements of mixed content that can contain a combination of elements, attributes or text. Elements that contain only text. 20 Example - Elements containing elements only .
21 Example Elements containing elements only
22 Referring to a group If we want to reuse a set of elements in several content type definitions, we can use a model group to define a set of elements that can be repeated. They act rather like parameter entities in DTDs. A model group consists of element declarations, wildcards and other model groups. The minimum values for min and maxOccurences = 1.
23 Using all
Billions Of StarsSusan Boggs19831-5555-555-2Anderson-WellsAdventures Of Freddie the FrogJohn Smith19770-444-4444-4Kidder Publishing Co. Publisher> 24 Attributes Attribute declarations:
An attribute is declared with . An attribute can be defined outside of a complex type and referenced in complex type. Attribute types can be defined using primitive types. Default, fixed, optional, required and prohibited can be used to set the values for attributes. Example: 25
26 xsd:element name="BookCatalog">
27 Uniqueness & Keys DTDs provide the ID attribute datatype for uniqueness (i.e., an ID value must be unique throughout the entire document, and the XML parser enforces this). XML Schema has much enhanced uniqueness capabilities: enables you to define element content to be unique. enables you to define non-ID attributes to be unique. enables you to define a combination of element content and attributes to be unique. enables you to distinguish between unique versus key. enables you to declare the range of the document over which something is unique 28
unique vs key Key: an element or attribute (or combination thereof) which is defined to be a key must: always be present (minOccurs must be greater than zero) be not-false. be unique Key implies unique, but unique does not imply key 29 Using ISBN as a Key In the next example, we will use a Book's ISBN element as a key. 30 Example
Billions Of StarsSusan Boggs19831-5555-555-2Anderson-WellsAdventures Of Freddie the FrogJohn Smith19770-444-4444-4Kidder Publishing Co. 32 Notes about It must be nested within an
It must come at the end of (after the content model, and attribute declarations) Use the element as a child of to select a set of elements for which the key applies. Use the element as a child of to identify the element or attribute that is to be the key There can be multiple elements. 33 Example meeting.xsd
34 Example-meeting.xml JohnSmithMaryJones 35 unique The element is used exactly like the element is
used. It has a and one or more elements, just like has. The only difference is that the schema validator will simply validate that, whenever present, the values are unique. 36 Example .
37 Referencing a key with a key ref Similar to ID/IDREFS, you can define a keyref to link an element with a key. If there are 2 fields in the key, then there must be 2 fields in the keyref, if there are 3 fields in the key, then there must be 3 fields in the keyref, etc. Further, the fields in the keyref must match in type and position to the key.
Lecture 4: Arithmetic overflow, Branches, Control Structures, Abstraction & Refinement ... unsigned subtract if the answer is wrong V set after a signed addition or subtraction if the answer is wrong Bit Name Meaning after add or sub N negative...
Cookies. Cookie types: Persistent session. first-party. third-party. You can control when and from whom cookies are accepted by specifying the level of privacy you want to maintain. You can view the file content of cookies to see information about the...
Fossil Fuels. Fossil fuels are energy-rich substances formed from the remains of organisms. Coal, Oil, and natural gas. Fossil fuels are made of hydrocarbons - chains of hydrogen and carbon. Combustion of fossil fuels provides more energy per kg than...
The totem pole stands in the center of the image, approximately 50 feet tall. A native American in a headdress and wrap stands to the left, while a man in a button-down shirt and tie stands to the right. A...
: START THE ASSESSMENT THAT WOULD MEASURE YOUR LEXILE READING LEVEL and answer ALL Questions AND CLICK NEXT AFTER EACH UNTIL YOU'VE COMPLETED THE ASSESSMENT. YOU WILL GET YOUR LEXILE SCORE IMMEDIATELY UPON COMPLETION OF THE ASSESSMENT. Thursday, February 28th,...
Edit the text with your own short phrase. Move the sparkles as you like. The animation is already done for you; just copy and paste the slide into your existing presentation. Note: This animation looks best on a dark background.
Ready to download the document? Go ahead and hit continue!