Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

XML's validation - XML Schema

2,466 views

Published on

Content:
- Structures
- Datatypes
References:
- Beginning XML, 5th Edition, Joe Fawcett, Liam R. E. Quin, Danny Ayers
- XML in a nutshell,3rd Edition, Elliotte Rusty Harold & W. Scott Means
- http://www.w3schools.com/

Published in: Education, Technology
  • http://www.dbmanagement.info/Tutorials/XML.htm
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • What do you want?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • یک مرورگر جدید دارای ترجمه خودکار را امتحان کنید.دانلود Google Chromeنادیده گرفتن





    ترجمه










    انگلیسی

    فارسی

    فرانسوی


    شناسایی زبان









    فارسی

    انگلیسی

    فرانسوی











    سلام
    ببخشید من میخواهم کار باxml را آموزش ببینم.
    لطفا کمکم کنید.






















    آیا منظور شما این است: سلام ببخشید من میخوام کار با xml را آموزش ببینم. لطفا کمکم کنید.









    Hi
    Sorry I train with the xml.
    Please help me.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

XML's validation - XML Schema

  1. 1. Validation – XML Schemas Nguyễn Đăng Khoa
  2. 2. Content • Document Type Definitions (DTDs) • XML Schemas
  3. 3. XML Schemas (XSD) • Define XML vocabularies and grammars • Describe the structure and content of XML documents in more detail than DTDs • XML Schema 1.0 specifications were first published by the W3C in 2001, with a second edition following in 2004 • XML Schema 1.1 became a W3C Recommendation in April 2012
  4. 4. XSD’s goals • Check XML document is valid or not
  5. 5. XSD – Benefits • Are created using basic XML • Fully support the Namespace Recommendation • Validate text element content based on built-in and user-defined data types • Create complex and reusable content models • Enable the modeling of programming concepts such as object inheritance and type substitution
  6. 6. XSD 1.0 - Specifications • Part 1: Structures (http://www.w3.org/TR/xmlschema-1/) • Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/)
  7. 7. XSD - Example
  8. 8. XSD – Namespace in XSD & XML
  9. 9. XSD – Explicitly namespace
  10. 10. XSD – Default namespace
  11. 11. XSD – XML doesn’t use namespace URI to xsd
  12. 12. XSD – XML uses namespace
  13. 13. XSD – XML uses namespace URI to xsdnamespace blank
  14. 14. XSD – XML uses namespace
  15. 15. XSD – XML uses namespace
  16. 16. XSD – Element and Attribute qualification
  17. 17. XSD – qualified vs. unqualified qualified unqualified
  18. 18. XSD – Global vs. Local Global Local
  19. 19. XSD – Global vs. Local • Global declarations are declarations that appear as direct children of the <schema> element. Global element declarations can be reused throughout the XML Schema. • Local declarations do not have the <schema> element as their direct parent and can be used only in their specific context.
  20. 20. XSD – elementFormDefault • qualified: nested elements must belong to the target namespace of the schema • unqualified is default value, a mix of qualified and unqualified elements
  21. 21. XSD – elementFormDefault – Example Valid
  22. 22. XSD – elementFormDefault – Example Invalid Element 'first': This element is not expected. Expected is ({http://www.example.com/name}first)
  23. 23. XSD – elementFormDefault – Example Valid
  24. 24. XSD – elementFormDefault – Example Invalid Element '{http://www.example.com/name}first': This element is not expected. Expected is (first)
  25. 25. XSD – attributeFormDefault – Example • Is same elementFormDefault • unqualified is default value
  26. 26. XSD – attributeFormDefault – Example Valid
  27. 27. XSD – attributeFormDefault – Example Invalid
  28. 28. XSD – attributeFormDefault – Example Invalid
  29. 29. XSD – Content Models • Is allowable content (type) of elements and attributes • There are 2 content models – <complexType> – <simpleType>
  30. 30. XSD - <complexType> • Defines types that contain attributes or elements • There are 3 ways of interpreting a list of elements – <sequence>: Elements must appear in the given order – <choice>: Only one of the elements in the list may appear – <all>: Elements can appear in any order, with each child element occurring zero or one time
  31. 31. XSD – <complexType> – Example
  32. 32. XSD – <complexType> – Example
  33. 33. XSD – Rule of <all> • The <all> declaration must be the only content model declaration that appears as a child of a <complexType> definition • The <all> declaration can contain only <element> declarations as its children – No <sequence>, <choice>, <group> in it • The <all> declaration’s children may appear once each in the instance document
  34. 34. XSD - <element>
  35. 35. XSD - <element> – Name
  36. 36. XSD - <element> – Type
  37. 37. XSD - <element> – Local Type include the type declaration as a child of the element declaration
  38. 38. XSD - <element> – Global Type
  39. 39. XSD - <element> – Cardinality
  40. 40. XSD - <element> – Cardinality Default: 1
  41. 41. XSD - <element> – Default value
  42. 42. XSD - <element> – Fixed value
  43. 43. XSD – Mixed Content • Enable you to include both text and element content within a single content model
  44. 44. XSD – Simple Content • Enable you to include only text within a single content model
  45. 45. XSD – Empty Content
  46. 46. XSD – Elements Wildcards • Suppose you want to specify that your element can contain any of the elements declared in your namespace, or any elements from another namespace
  47. 47. XSD – Elements Wildcards List of namespace URIs
  48. 48. XSD – Elements Wildcards indicate that any element from the schema’s target namespace can be used
  49. 49. XSD – Elements Wildcards indicate that elements not in any namespace can be used
  50. 50. XSD – Elements Wildcards indicate that all elements from any namespace or no namespace are allowed
  51. 51. XSD – Elements Wildcards indicate that elements from namespaces other than the schema’s target namespace can be used
  52. 52. XSD – Elements Wildcards (Default) Elements represented by this <any> element must be declared. Furthermore, the element must be valid according to its declaration
  53. 53. XSD – Elements Wildcards Elements represented by this <any> element need not be declared in the schema and need not be valid even if they are declared
  54. 54. XSD – Elements Wildcards Elements represented by this <any> element must be validated if they are declared, but must not be validated if they are declared
  55. 55. XSD – Elements Wildcards – Rules • The <any> declaration can appear only within a content model. • You are not allowed to create global <any> declarations
  56. 56. XSD – <group> • Enable you to define reusable groups of elements
  57. 57. XSD – Exercise - No namespace
  58. 58. XSD – Exercise – Use namespace
  59. 59. XSD - <attribute>
  60. 60. XSD - <attributeGroup> • Enable you to define reusable groups of attributes
  61. 61. XSD – Built-in Data Types
  62. 62. XSD – Built-in Data Types
  63. 63. XSD – Built-in Data Types
  64. 64. XSD – Built-in Data Types
  65. 65. XSD – Built-in Data Types
  66. 66. XSD – Built-in Data Types • In addition to the types listed, the XML Schema Recommendation also allows the types defined within the XML Recommendation – ID – IDREF – IDREFS – ENTITY – ENTITIES – NOTATION – NMTOKEN – NMTOKENS
  67. 67. XSD – Exercise
  68. 68. XSD – User-Defined Data Types • When you declare a <simpleType>, you must always base your declaration on an existing data type – Built-in – Custom • <simpleType> definitions are often called derived types. There are three primary derived types: – Restriction types – List types – Union types
  69. 69. XSD – User-Defined Data Types prevent a simple type from being subtyped
  70. 70. XSD – Restriction Type • is a subset of its base type Facet
  71. 71. XSD – Restriction Type – Constraining FacetsConstraint Description enumeration Defines a list of acceptable values fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value) maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value) maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value) minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value) minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero pattern Defines the exact sequence of characters that are acceptable totalDigits Specifies the exact number of digits allowed. Must be greater than zero whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled Ref: http://www.w3schools.com/schema/schema_facets.asp
  72. 72. XSD – List Type • create a list of items
  73. 73. XSD – Union Type • allow potential values for elements and attributes to have any of several types
  74. 74. XSD – Union Type

×