1.08k likes | 1.23k Views
XML Schema 1.1 for Managers. Roger L. Costello http://www.xfront.com 3 December, 2012. Purpose. The purpose of this tutorial is to give an overview of the new features of XML Schema 1.1 without getting into its syntax. It is targeted to managers.
E N D
XML Schema 1.1 for Managers Roger L. Costello http://www.xfront.com 3 December, 2012
Purpose • The purpose of this tutorial is to give an overview of the new features of XML Schema 1.1 without getting into its syntax. • It is targeted to managers. • I show how these new technical features can benefit your business.
Your 1.0 Schemas will still work An XML document conforming to a 1.0 schema can be validated using a 1.1 validator, but an XML document conforming to a 1.1 schema might not validate using a 1.0 validator. XML Schema 1.1 XML Schema 1.1 is a superset of XML Schema 1.0 XML Schema 1.0
XML Schema 1.1 Validators • The schema-aware version of SAXON (version 9.3 or later) supports the full XML Schema 1.1 specification: http://www.saxonica.com/ • Apache XERCES supports XML Schema 1.1:http://xerces.apache.org/xerces2-j/ • You can create XML Schema 1.1 schemas today!
Status • XML Schema 1.1 became a standard on April 5, 2012 (the W3C calls it a “recommendation” not a standard, but they are the same)
Technology Stack XML Schema 1.1 XML Schema 1.0 Each technology assumes you know the technologies beneath it. XPath Namespaces XML
Review: Purpose ofXML Schemas
app XML app app app XML XML app ship the XML "shred" app Two uses of XML • XML as a temporary transport vehicle: • As soon a the XML gets to its destination the data is extracted and put into a permanent storage mechanism (such as a database). • Applications operate on the data in the permanent storage. • XML as permanent storage: • Applications operate directly on the XML.
app XML XML app ship the XML "shred" app XML as a temporary transport vehicle An XML Schema can be used as a contract between the sender and the receiver: "Here's the information we agree to exchange, and the format of the information."
XML app XML app Rob Jill Anthony Sally Pete app XML as permanent storage Often occurring in the form of a workflow:
XML as permanent storage(cont.) XML app1 app2 app3 app4 Each application does a "unit of work." It is desirable, after each unit of work, to assess the system. XML Schemas can be used to check each application's output.
I envision systems working like this: Check the information–validate that no rules are being broken. Do some work. Then validate that no rules have been broken (as a result of the work), i.e., check that you’re still on track. Then do another unit of work. Then validate again. Then do another unit of work. Then validate again. And so forth.
Rules • We live in a world of rules: • Driving: we follow the rules of the road • Queues: we form lines at banks and in the checkout lanes at the supermarket • Taxes: accountants spend lots of time each year learning the new tax rules • Laws: our legal system enforces societies' laws • Rules guide our actions. • Rules let us know if we are on or off track.
Rules are Important All enterprise work as it grows toward perfection becomes rule-based Roger Costello and Bob Wilson
XML Schema = Rules • XML Schemas is all about expressing rules: • rules about what data is allowed • rules about how the data must be organized • rules about the relationships between data
Example: My Vacation <Vacation> <Trip segment="1" mode="air"> <Transportation>airplane</Transportation> </Trip> <Trip segment="2" mode="water"> <Transportation>boat</Transportation> </Trip> <Trip segment="3" mode="ground"> <Transportation>car</Transportation> </Trip> </Vacation>
Validate <Vacation> <Segment id="1" mode="air"> <Transportation>airplane</Transportation> </Segment> <Segment id="2" mode="water"> <Transportation>boat</Transportation> </Segment> <Segment id="3" mode="ground"> <Transportation>car</Transportation> </Segment> </Vacation> Validate the XML document against the XML Schema XML Schema Rule 1: A vacation has segments. Rule 2: Each segment is uniquely identified. Rule 3: There are three modes of transportation: air, water, ground. Rule 4: Each segment has a mode of transportation. Rule 5: Each segment must identify the specific mode used.
Desirable Rules Transportation mode Rule: if mode = air then transportation must be either airplane or hot-air balloon. Similar rules for water and ground. airplane, hot-air balloon air boat, hovercraft water car, bicycle ground
XML Schema 1.0 cannot detect this error <Segment id="1" mode="air"> <Transportation>boat</Transportation> </Segment> These are inconsistent. Error! Why can’t the error be detected using XML Schema 1.0? Answer: Because the rule on the preceding slide cannot be expressed.
XML Schema 1.1 • Much more powerful than 1.0 • Can express many more rules (The rule on the preceding slide can be expressed!) • Let's see the new features that 1.1 provides …
New Feature:Express Business Policies and Rulesusing Assertions
Example Policy Level 1 managers may sign off on purchase requests that do not exceed $10K. Level 1 managers may sign off on purchase requests that do not exceed $10K.
This doesn't conform to company policy <purchase-request> <item>Widget</item> <cost>15000</cost> <signatureAuthority>Level 1</signatureAuthority> </purchase-request>
Validate XML Schema Level 1 managers may sign off on purchase requests that do not exceed $10K. XML Schema Validator invalid! <purchase-request> <item>Widget</item> <cost>15000</cost> <signatureAuthority> Level 1 </signatureAuthority> </purchase-request>
XML Schema 1.0 • With XML Schema 1.0 business policies and rules could not be expressed. • The policy rule on the previous slides could not be expressed. • Consequence: developers buried policies and rules in procedural code. Java program Level 1 managers may sign off on purchase requests that do not exceed $10K.
Disadvantage #1 of Buried Policies and Rules I don't understand Java. I can't change the policy. Argh! Java program Policy, expressed in Java code Business Person
Disadvantage #1 of Buried Policies and Rules Difficult to change policies and rules.
Disadvantage #2 of Buried Policies and Rules How much can I sign off on? Java program Manager Policy, expressed in Java code
Disadvantage #2 of Buried Policies and Rules The policies and rules are expressed in code instructions and are less visible – perhaps only the programmer knows the rules.
XML Schema 1.1 • In XML Schema 1.1 policies and rules can be expressed. • Policies and rules are declaratively expressed. • Consequence: - Policies and rules can be easily changed - Policies and rules are transparent
Example Business Rule Level 1 managers may sign off on purchase requests that do not exceed $10K. No paragraph may have a security classification higher than the document's classification.
top-secret is higher than secret is higher than confidential is higher than unclassified
Example Document <Document classification="secret"> <Para classification="unclassified"> ... </Para> <Para classification="secret"> ... </Para> <Para classification="unclassified"> ... </Para> <Para classification="secret"> ... </Para> </Document> Ensure that no <Para> element has a classification higher than the <Document> element's classification
XML Schema 1.0 versusXML Schema 1.1 • In XML Schema 1.0 you cannot express the rule on the previous slide. • In XML Schema 1.1 you can express it.
XML Schema 1.0 Grammar checks XML Schema 1.1 Business rule checks
XML Schema 1.0 versusXML Schema 1.1 • With XML Schema 1.0 you can express grammar (syntax) constraints, e.g., this markup should occur in this order, that data should be a date, and so forth. • With XML Schema 1.1 you can still express grammar constraints but you can also express data relationships (business rules), e.g., the classification value here must be less than the classification value there.
New Feature assertion
Express Policies and Rules using Assertions Policies and rules are expressed in XML Schema 1.1 using assertions, e.g.,Assertion: Level 1 managers may sign off on purchase requests that do not exceed $10K.Assertion: No paragraph may have a security classification higher than the document's classification.
Review • We've examined the first new feature in XML Schema 1.1, the ability to express policies and rules using assertions. • This feature is a big benefit to businesses: now businesses can declaratively express their policies and rules in XML Schemas rather than burying them in procedural code.
New Feature:Creating Department-SpecificData using Conditional Type Alternatives
Example of Conditional Content Human Resources (HR) Department: For each employee store this data: name, date of hire, employee number, and emergency contact telephone number. Level 1 managers may sign off on purchase requests that do not exceed $10K. Information Technology (IT) Department: Level 1 managers may sign off on purchase requests that do not exceed $10K. For each employee store this data: name, areas of expertise, and current project.
Content varies, depending on dept. <Employee dept="HR"> </Employee> <Employee dept="IT"> </Employee> <Name>John Doe</Name> <Hire-Date>2000-01-01</Hire-Date> <Employee-Num>123</Employee-Num> <Emergency-Contact>617-123-4567</Emergency-Contact> <Name>John Doe</Name> <Expertise>XML, XML Schema</Expertise> <Project>upgrade xyz interface</Project>
If it's HR then the content must be an HR type. If it's IT then the content must be an IT type. <Employee dept="_________"> </Employee>
Conditional Content The content of Employee is conditional to the value of dept.
Example #2 <Publication kind="book"> </Publication> <Publication kind="magazine"> </Publication> <Title>Origin of Wealth</Title> <Author>Eric D. Beinhocker</Author> <Date>2006</Date> <ISBN>1-57851-777-X</ISBN> <Publisher>Harvard Business School Press</Publisher> <Genre>Scientific</Genre> <Circulation>733,000</Circulation> <Founded>1845-08-28</Founded> The content of Publication depends on the kind of publication.
If it's magazine then the content must be a Magazine type. If it's book then the content must be a Book type. <Publication kind="_________"> </Publication>
Conditional Content The content of Publication is conditional to the value of kind.
New Feature alternative
Express Conditional Content using Alternative Conditional content is expressed in XML Schema 1.1 using alternatives, e.g.,Alternative: if kind="magazine" then the content is a Magazine type.Alternative: if kind="book" then the content is a Book type.
Review • We've examined two new features in XML Schema 1.1: • the ability to express policies and rules using assertions • the ability to express conditional content using alternatives