Geoinformatics - PowerPoint PPT Presentation

geoinformatics n.
Skip this Video
Loading SlideShow in 5 Seconds..
Geoinformatics PowerPoint Presentation
Download Presentation

play fullscreen
1 / 32
Download Presentation
Download Presentation


- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Geoinformatics W3 XML Schema

  2. W3C XML Schema • XML Schema (XSD), which follows the structure of a well-formed XML document, is a simpler alternative to the DTD which uses non-XML special constructs (won’t discuss it) • The self-describing XSD, which provides a large set of datatypes, is more expressive and easier than DTD, and is optimized for interoperability and web applications • XSD also supports inheritance and datatyping which DTDs do not provide. Because the XSD file is a text file, it can easily be transferred on the Web through FTP and HTTP • This, and its impressive set of data types make the XML Schema an excellent choice for interoperability among applications using XML on the Web

  3. Declaring elements • Elements are declared in XSD with the <xs:element>tag • Elements can be defined locally or globally, allowing them to be referred to within an element only, or from anywhere throughout the schema, respectively

  4. Example • The following short schema, which defines only one FaultType element, has an XML declaration for version and encoding, and ‘xs’ namespace for the XML schema • Notice that the root element is the schema element • Also notice that it uses the ‘xs’ namespace prefix to define the element and two attributes <? xml version=”1.0” encoding=”utf-8”?> <xs:schemaxmlns:xs=””> <xs:element name=”NormalFault” type=”Fault”/></xs:schema>

  5. Attributes of the <xs:element> • The xs:element has several important attributes that include: name, type, fixed, default, id, maxoccurs, minoccurs, nillable, ref, and substitutionGroup, e.g., <xs:elementname=”FaultType” type=”xs:string”/> • These attributes define the name and the XSD datatype for the element (e.g., string, integer) • In other words, the attributes, provide information about the instances of the element, and can control the properties of the element

  6. Element name and type • The ‘name’ attribute gives a name to the element, for example: <xs:elementname=”ThrustFault” type=”Fault”/> declares the <ThrustFault> element of type Fault • Names should follow the XML naming rules • The ‘type’ attribute specifies the type for the element, and can take a namespace (i.e., xs:string)

  7. Naming rule • Valid element name, which are case sensitive, should start with a letter or underscore, and can include letters (including those with accents), numbers, underscore, dot, or hyphen, but no spacing • The following are all valid XML names: <bodyOfWater>, <Ductile-deformation>, <Fenêtre>, and <magma2solid> • Examples of invalid names are: <2ndRidge>, <strike&dip>, <XMLdoc>, <deformation structure>, and <y=x+6>

  8. Default attribute • The ‘default’ attribute specifies a default value for the element <xs:elementname=”CarbonateComposition” default=”CaCO3”/> creates an element called <CarbonateComposition>, which, in the absence of other information, has a ‘CaCO3’ default value • This means that the default value can change, e.g., to MgCa(CO3)2, if other information is given

  9. ‘fixed’ attribute • The ‘fixed’ attribute provides an initial, fixed string value for the element that cannot change <xs:elementname=”Fault” fixed=”A plane of displacement”/> will provide the fixed attribute for all instances • The fixed attribute cannot change by the author of an XML document which uses the XSD element

  10. id, maxOccurs, and minOccurs attributes • The ‘id’ attribute specifies an ID, i.e., a unique identifier, for the element, and has the XSD ‘id’ datatype type • The ‘maxOccurs’ and ‘minOccurs’ specify the cardinality, i.e., the max & min number of times the element can be in the document • The default value for both of these attributes is ‘1’, which can change with new information if it is declared, e.g., the following: <xs:elementname=”Limb” minOccurs=”2” maxOccurs=”10”/> which declares the Limb element (of the Fold element), specifies that the document should have between 2 and 10 Limb elements • Each time we want to provide data for a fold, we can enter data for 2 to 10 limbs for the fold (need at least 2 to determine the fold axis)

  11. nillable and ref attributes • The ‘nillable’ attribute, with a default value of ‘false’ (i.e., not nillable), is a Boolean attribute of the XSD:nil type, which specifies an empty element • The ‘ref’ attribute is used to reuse existing global elements • To do this, we first need to define an element at a global scope (e.g., Formula), i.e., the element is not declared within the content of another element, and then reference it with the ‘ref’ attribute inside another element (e.g., Mineral)

  12. Example <?xml version="1.0" encoding="UTF-8"?><xs:schemaxmlns:xs=""> <! - - define Formula at global scope -- > <xs:elementname="Formula" type="xs:string"/> <! - - define Mineral, and use Formula - - > <xs:complexTypename="Mineral"> <xs:sequence> <xs:elementref ="Formula"/> </xs:sequence></xs:complexType></xs:schema>

  13. SubstitutionGroup attribute • The ‘substitutionGroup’ attribute is used to create a set of elements that can substitute a head element, provided that they have the same type as the head element • The substitutionGroups attribute must reference the head element for each substituting element • For example, let’s say that we want to represent the information about minerals in two different forms: with just their name, using the PartialMineralName element, which just uses the globally defined Mineral head element, and fully, by their name, formula, type, etc, using the FullMineralInfo, which modifies the head element

  14. <!- - assume the head Mineral element is declared globally --><xs:elementname=”MineralInfo”/> <!- - Define PartialMineralInfo & FullMineralInfo elements to substitute --> <xs:elementname=”PartialMineralInfo” type=”xs:string” substitutionGroup=”MineralInfo”/> <xs:elementname="FullMineralInfo" substitutionGroup="MineralInfo"> <xs:complexType> <xs:all> <xs:elementname="MineralName" type="xs:string" minOccurs="1"/> <xs:elementname="MineralFormula" type="xs:string" minOccurs="0"/> <xs:elementname="MineralType" type="xs:string" minOccurs="1"/> <!-- more elements here --> </xs:all> </xs:complexType> </xs:element>

  15. Now the two elements: PartialMineralInfo and FullMineralInfo can be used wherever the MineralInfo element is used. For example, assume that the element Rock element uses the MineralInfo element: <?xml version="1.0" encoding="UTF-8"?><xs:schemaxmlns:xs=""><xs:elementname="Rock"> <xs:complexType> <xs:sequence> <xs:elementref="MineralInfo"/> </xs:sequence> </xs:complexType></xs:element></xs:schema>

  16. Content of an element • If an elements only has text or a value as content, it has asimpleContent • If it has sub-elements, then it has an element content • If it has a mixture of text or value and sub-elements, then it has a mixed content • The elements can be annotation, simpleType, or complexType • Annotation is a more extended version of the comment, and is used to provide documentation for the element. For example: <xs: annotation> <xs: documentation> A mineral is a naturally occurring, crystalline, inorganic and solid substance with a specific range of chemical composition. </xs: documentation></xs: annotation>

  17. <SimpleType> • The simpleType element allows making simple content with ability to restrict existing datatype such as xsd: integer • The simpleType element can contain a restriction, a list, or a union • The simpleType element has some attributes that include ‘id’ and ‘type’ • For example, make the global ‘DipAmount’ element by restricting the integer datatype to take a value from 0 to 90; could be reused in other elements <xs:elementname="DipAmount"> <xs:simpleType> <xs:restrictionbase="xs:int"> <xs:minInclusivevalue="0"/> <xs:maxInclusivevalue="90"/> </xs:restriction> </xs:simpleType></xs:element>

  18. <xs:list> • Can use xs:list to make a simpleType element which can take a multiple set of values. • For example, let’s say we want to let the users enter a list of 3 minerals for a rock. Here is how we do it: <xs:elementname=“Mineral"> <xs:simpleType> <xs:listitemType="xs:string"> <xs:restriction> <xs:minLength value="1"/> <xs:maxLength value ="3"/> </xs:restriction> </xs:list> </xs:simpleType> </xs:element> • The minLength and maxLength define the length of the list, not that of the string. In this case, a valid list would have 3 minerals in it: <Mineral> quartz feldspar muscovite </Mineral>

  19. xs:union • A union is used to combine two simpleType elements into one • The value of the union element is part of the values of the two joined elements • For example, in the next slide, we first define two restricted simpleType elements, the first one describes the particle size names, and the second one describes the range, in mm for these particle sizes • We then use a union to combine them into the ParticleSize element

  20. < ! - - define the simple type for particle size - -> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="gravel"/> <xs:enumeration value="sand"/> <xs:enumeration value="silt"/> </xs:restriction> </xs:simpleType> < ! - - define the simple type for the range of values - -> <xs:simpleType> <xs:restriction base ="xs:decimal"> <xs:minInclusive value="0.004"/> <xs:maxInclusive value="2.00"/> <xs:fractionDigits value="2"/> </xs:restriction></xs:simpleType>

  21. < ! - - now union the two simple types - -> <xs:attributename=”ParticleSize”><xs:simpleType> <xs:union><xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="gravel"/> <xs:enumeration value="sand"/> <xs:enumeration value="silt"/> </xs:restriction> </xs:simpleType><xs:simpleType> <xs:restriction base ="xs:decimal"> <xs:minInclusive value="0.004"/> <xs:maxInclusive value="2.00"/> <xs:fractionDigits value="2"/> </xs:restriction> </xs:simpleType> </xs:union></xs:simpleType></xs:attribute>

  22. Now use the attribute made by the union of the two simpleTypes: <xs:elementname=“ClastSize"> <xs:compleType> <xs:complexContent> <xs:attributeref="ParticleSize"/> </xs:complexContent> </xs:compleType></xs:element>

  23. Deriving new datatypes • W3C XSD Schema provides an impressive set of standard datatypes that guarantee data integrity and interoperability among xml applications • The URI for the namespace related to these XSD datatypes is: • The ‘xs’ xml namespace (xmlns) prefix is associated with this URI in the schema of the XSD schema: <xs:schemaxmlns:xs=””>

  24. Defining our own datatype • We can derive our own simpletype and complexTypedatatypeseither by extending or restricting the existing primitive, built-in datatypes • That is, we use the primitive datatypesas a base during extension and restriction • The primitive datatypes include: string, boolean, decimal, date, and time, among many others • Each one of these primitive datatypes has one or more attributes which are modified when they are being extended or restricted

  25. Examples • For example, the xs:stringdatatype has the following attributes: length, minLength, maxLength, pattern, and enumeration • The xs:decimaldatatype has the following attributes: totalDigit, fractionDigits, minInclusive, maxInclusive, minExclusive, maxExclusive • The set of these datatypes is too big to be covered here, and the reader is encouraged to consult the following URL for information about these types:

  26. Deriving simpleTypedatatypes • New simpleTypedatatypes can only be derived through restriction of the existing primitive datatypes • This is done by modifying the attributes of each primitive datatype • For example, we can derive the list of the planets in the solar system in the SolarSystemPlanetsimpleTypedatatype, by restricting the enumeration attribute of the xs:string as follows:

  27. List of the planets <?xml version="1.0" encoding="UTF-8"?><xs:schemaxmlns:xs=""> <xs:elementname="SolarSystemPlanets"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Mercury"/> <xs:enumeration value="Venus"/> <xs:enumeration value="Earth"/> <xs:enumeration value="Mars"/> <xs:enumeration value="Jupiter"/> <xs:enumeration value="Saturn"/> <xs:enumeration value="Uranus"/> <xs:enumeration value="Neptune"/> </xs:restriction> </xs:simpleType> </xs:element></xs:schema>

  28. Deriving complexTypedatatypes • Derivation of new complexTypedatatypes can be done through both extension and restriction of the existing primitive types • In the following, a CylindricalFold complex datatype is first derived by restriction • Cylindrical folds have axis, which is the same thing as the hinge line, and has an axial plane • The CylindricalFoldcomplexType is then restricted by deriving a new datatype called NonCylindricalFold, which is a fold that has no axis, but instead has one or more hinge lines, and instead of the axial plane, it has several hinge planes, each measurable with a combination of an axial trace and the hinge line

  29. CylindricalFold <xs:complexTypename="CylindricalFold"> <xs:sequence> <xs:elementname="limb1" type="xs:string"/> <xs:elementname="limb2" type="xs:string"/> <xs:elementname="axis" type="xs:string" maxOccurs="1"/> <xs:elementname="axialPlane" type="xs:string" maxOccurs="1"/> </xs:sequence> </xs:complexType> </xs:schema>

  30. NonCylindricalFold • Here is the structure of the CylindricalFold and NonCylindricalFold derived datatypes. Notice that restriction is inside the xs:complexContent <?xml version="1.0" encoding="UTF-8"?><xs:schemaxmlns:xs=""><xs:complexTypename="NonCylindricalFold"> <xs:complexContent> <xs:restriction base="CylindricalFold"> <xs:sequence> <xs:element name="limb1" type="xs:string"/> <xs:element name="limb2" type="xs:string"/> <xs:element name="axis" type="xs:string" maxOccurs="0"/> <xs:element name="axialPlane" type="xs:string" maxOccurs="0"/> </xs:sequence> </xs:restriction> </xs:complexContent></xs:complexType>

  31. Derivation by extension • The complexTypedatatypes can be derived by extension, by adding say a new attribute or element to the base type • For example, we can derive the ConjugateKinkFoldcomplexType by extending the CylindricalFold to have a new attribute that has a default value “straight limb and angular hinge” • There is also a new element, called limb3 • The axis and the axial plane elements are restricted to have two occurrences, to account for the two intersecting axial planes of a conjugate box fold, by setting their maxOccur attribute to hold a value of 2

  32. ConjugateBoxFold <?xml version="1.0" encoding="UTF-8"?><xs:schemaxmlns:xs=""><xs:complexTypename="ConjugateBoxFold"> <xs:complexContent> <xs:extension base="CylindricalFold"> <xs:attributename="style" default="straight limb and angular hinge"/> <xs:sequence> <xs:element name="limb1" type="xs:string"/> <xs:element name="limb2" type="xs:string"/> <xs:element name="limb3" type="xs:string"/> <xs:element name="axis" type="xs:string" minOccurs="2"/> <xs:element name="axialPlane" type="xs:string" minOccurs="2"/> </xs:sequence> </xs:extension> </xs:complexContent></xs:complexType></xs:schema>