Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.

Similar presentations


Presentation on theme: "XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the."— Presentation transcript:

1 XML – Part III

2 The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the element include: ‘id’, which provides a unique id for the element ‘mixed’, a Boolean that indicates whether the element has a mixed content or not (the default value is false), and ‘name’, which gives a name to the element

3 complexType’s children elements The children elements of the element can be:

4 simpleContent … The simpleContent allows the complexType element to have leaf nodes of character data, without any child element The content of a simpleContent element must either be: extension or restriction of an existing built in or derived datatypes As an example for using extension, we can make a complexType element called RockName by extending the built in string datatype in the simpleContent element The RockName element (next slide) can only have character data as its value

5 complexType by simpleContent by extension

6 complextype by simpleContent by restriction As an example for using a restriction in the simpleContent of a complexType, we can define the complexType called CelciusTemperature by restricting the xs:decimal number to have a minimum value of -273.15 o C

7 complexType with complexContent The complexType element with complexContent can be built by adding element content, or a combination of child elements and character data, i.e., mixed content This is done by defining a list of elements and attributes The following is an example of a complexType element called MineralInfo with an element content, using the which defines the order that the child element should appear Note that in this example, there is no need to have the element at all. We can just put the in the

8 complexType w/ element content --> -->

9 Mixed content We can now build a mineralogy element whose type is MineralInfo. To build a mixed content element we set the ‘mixed’ attribute of the element to ‘true’ This allows us to add text nodes before, between, and after the child nodes In the following, we define a Rock element that allows writing the description of the rock in text, anywhere in the document

10 Example of mixed content

11 The element provides a mandatory order to the sequence of elements in a complex type. For example, to force the dip to follow the strike of a planar structure, we can use the sequence element to do just that

12 Let’s say that some geologists provide dip direction and dip amount, instead of strike and dip for a planar feature, and we want to give them this option to enter their data. We do it as follows:

13 XML instance document Because of the choice, we may have either one of the following in an instance document: N30E 65SE or S60E 65

14 In contrast to the element, the element does not put any restriction on the ordering of its sub-elements However, the element must be at the top-level, and cannot contain, or be part of, a sequence or a choice For example, we can define the ‘Structure’ element to have a set of elements in any order This means that an instance document can have any of the Name, Type, and Attitude listed in any order

15 Example for

16 Attributes In W3C XSD schema, the attributes are declared with the element, which has its own attributes Local attributes can be declared within a certain element, as opposed to those that have a global scope, which are declared in the element, and that could be used by any element or attribute group For example, we can define the local ‘TemperatureType’ attribute for the Temperature element, to indicate the type of the temperature system (Celcius, Farenheit, etc.) This attribute can only be referenced by instances of the Temperature element

17 Local attribute

18 Attributes of the The attribute element has several attributes of its own, and include name, type, default, fixed, id, ref, and use: The ‘name’ attribute of the element specifies the name for the attribute, which needs to be a valid XML name, e.g., Notice that the type for the attribute is given by the W3C XSD string datatype We can have two attributes with the same name only if their type is different, and defined in different content (one for an element, and the other as an attribute)

19 The ‘type’ attribute specifies the simple built-in or derived (i.e., restriction of simple types) datatype for the attribute in the instance document These datatypes include (there are many more): boolean, integer, decimal, float, date, time, and string. Contrary to the elements, attributes cannot have complex types

20 The ‘default’ attribute of the element assigns a preset value to the attribute if no value is given in the instance document For example, we can define an attribute for kink bands to specify their straight limb and angular hinge as follows: Or, we can define the sample attribute with a default value of ‘rock’ as follows: In this case, if not specified, the sample type will be assigned to ‘rock’. Note: there might be other sample types: water, soil, etc.

21 If we want the value of an attribute not to change, we use the ‘fixed’ attribute For example, if we want the formula for quartz to always be SiO 2, we can fix it as follows:

22 The id attribute specifies a unique identifier for the attribute The id can then be referenced by other elements Notice that an attribute can also be referenced by its name The ref attributes allows referencing another attribute For example, let’s say we have a complexType aquifer element, which has two types: confined and unconfined, each with its own set of attributes that are of type ref, which reference the porosity and permeability attributes Notice that the references to the porosity and permeability attributes are global because they are declared in the schema element before the porosity and permeability are declared

23

24 The ‘use’ attribute specifies the usage of the with its own ‘optional’, ‘prohibited’, and ‘required’ attributes The default value for the ‘use’ attribute, when none of these is defined, is ‘optional’ Contrary to the ‘required’ value, which specifies that the attribute must be present, the prohibited value indicates that the attributes should not be used at all In addition to the ref attribute which allows referencing and reuse of attributes, we can structure and reference a group of attributes by the For example, we can structure information about folds in a group called FoldInfo, and then reference it with the name of the group in an element called Measurement

25

26 Enumerations Enumeration is a list of options that a user can select from For example, we can enumerate the exhaustive list of the types for minerals We define an attribute called mineralType that has an enumeration of the mineral types We then reference this attribute in the Mineral element Notice that enumeration is a restriction of a simpleType

27

28 Linking XSD schemas with instance documents The XML processor that manipulates an instance documents uses a special namespace that carries information on identifying the location and type of the associated schema The namespace URI for the instance document: http://www.w3.org/2001/XMLSchema-instance This has the xsi prefix (Note: ‘i’ stands for ‘instance’). The xsi namespace has four attributes: xsi:type, xsi:nil, xsi:schemaLocation, and xsi:noNamespaceSchemaLocation

29 The xsi:type attribute assigns a type to the instance of specific elements in the document The xsi:nil takes a Boolean value to indicate that an empty element is valid The xsi:schemaLocation specifies the location of the XSD schema for the document, with two URIs: the targetNamespace for the schema the URI that points to the location of the schema The xsi:noNamespaceSchemaLocation is used to locate schemas (similar to the xsi:schemaLocation) that have no namespace

30 For example, assume that we want to make an instance document from the following schema which has a Structure root element, with three elements of string type

31 A valid instance document based on the schema on the previous slide would look like the following: Brevard Fault 045, 30NW

32 XSL Transformation Well-formed XML documents (i.e., those having a valid XML syntax) can be viewed with an XML document reader, such as the Internet Explorer (by double-clicking the file in the Windows Explorer) Although, very useful, rendering the XML document in a browser shows all the tags, and looks very cluttered. Because XML concentrates on document structure and not presentation, it has the XSL (XML Stylesheet Language) standard which allows manipulation of the XML documents, and their controlled display on XML browsers or editors

33 XSL allows rendering the XML content into HTML, or tabular and other formats. XSL is a more sophisticated XML styling language, using a scripting language XSLT), compared to CSS (Cascading Style Sheets) which was originally designed for HTML Both have rules for say font size and color that are applied or associated to an XML document.


Download ppt "XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the."

Similar presentations


Ads by Google