2a.1 a review of the xml mark-up language copyright b. wilkinson, 2008. this material is the...

48
2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC- Charlotte) and is for the sole and exclusive use of the students enrolled in the Fall 2008 Grid computing course broadcast on the North Carolina Research and Education Network (NCREN) to universities across North Carolina. Sept 29, 2008

Upload: loreen-burns

Post on 13-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.1

A review of the XML mark-up language

Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and is for the sole and exclusive use of the students enrolled in the Fall 2008 Grid computing course broadcast on the North Carolina

Research and Education Network (NCREN) to universities across North Carolina. Sept 29, 2008

Page 2: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.2

Questions

1. Put your and up if you know HTML

2. Put your hand up if you know XML

If yes to both, next part will be easy.

Page 3: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

XML Mark-up Language

Use in Grid computing:

Already seen informally in:•Job submission and scheduling

• Job description languages

Will shortly see in:

• Software Infrastructure• Web Services Description• Deployment Description

2a.3

Page 4: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

Mark-up languages

• A way of describing information in a regular format that can be read by computer or humans

• Uses “tags’ that identify and delinerate information

• Enable information to be interpreted and processed by computer programs in a platform-independent way.

• Concept developed in 1960’s and 1970s notably with IBM’s mark-up language Generalized Markup Language (GML) developed in the 1960s.

2a.4

Page 5: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.5

Standard Generalized Mark-Up Language (SGML)

A mark-up language specification ratified in 1986.

• Key aspect – Using pairs of tags that surround information - a begin

tag <tag_name> and a matching end tag </tag_name> .

Example

<title> Grid Computing </title>

Begin tag End tag

Information (body)

Page 6: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

Mark-up languages

• Note the / in the end tag.

• When using multiple tag pairs, they must be nested properly.

• Different mark-up languages will use specific names for their tags.

2a.6

Page 7: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.7

HyperText Markup Language (HTML)

A mark-up language used in web pages.

“Hypertext” refers to the text’s ability to link to other documents.

“Markup” refers to providing information to tell browser how to display page and other things.

Page 8: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.8

HTML page format

<HTML><HEAD>

</HEAD><BODY>

</BODY></HTML>

Signifies an HTML document

Head section includes information about document - “metadata”

Body section contains text and references to images to be displayed

End of document

Page 9: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.9

HTML Tags

• Tags specify details such as type of text.

Example

<B> to start bold text </B> to end bold text

<I> to start italic text </I> to end italic text

Some tags in HTML are not in pairs

<BR> Line break tag

<P> New paragragh (line break + blank line)

Page 10: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.10

HTML page<HTML><HEAD>

</HEAD><BODY>

Hello world<BR><I> My name is <B>Tom</B> </I>

</BODY></HTML>

Page 11: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.11

QuestionWhat does the previous HTML page display?

Answer

Hello WorldMy name is Tom

Page 12: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.12

Attributes

Many tags can have attributes which specify something about the body between tag pair.

Example

<FONT COLOR=red SIZE=3 FACE=Times>This text is displayed in red in Times font, about 12 pt.</FONT>

Attributes

Page 13: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.13

XML(Extensible Mark-up Language)

• Ratified in 1998 - very important standard mark-up language - a “simplified” SGML.

• Developed to represent textual information in a structured manner that could be read and interpreted by a computer or a human.

• A foundation for Web services.

Page 14: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.14

Some key aspects of XML

• Tags always used in pairs delineate information to make it easy to process.

- Exception: when body between tags holds nothing. Then a single tag <tag_name/> can be used.

• Tags can be nested

• Names of tags not predefined as in HTML, but defined usually in a separate document called a schema.

• Creates multitude of “XML” languages.

Page 15: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.15

XML Tag Attributes

• As in HTML, attributes provide a way of providing information rather than in body between the tags.

• Use of attributes rather than the body is application dependent.

• Often have both attributes and a body.

Page 16: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.16

XML documents can be created by humans or automatically by computer.

In our application, they are processed by computer.

As we shall see, even when generated by computer programs, programmers still have to be able to read these documents to fully understand what’s going on.

Page 17: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.17

Sample XML document - A purchase order

<purchaseOrder id=“53912” date=“2004-08-05”><billTo>

<name>Department of Computer Science</name><company>University of North Carolina at Charlotte</company><street> 9201 University City Blvd.</street><city>Charlotte</city><state>NC</state><postalCode>28223</postalCode>

</billTo><shipTo>

<name>Department of Computer Science</name><company> University of North Carolina at Charlotte </company><street>9201 University City Blvd.</street><city>Charlotte</city><state>NC</state><postalCode>28223</postalCode>

</shipTo><items> <item productCode=“456-CS”>

<description>computer model 1234 </description><quantity>3</quantity><price>1234.78</price>

</item></items></purchaseOrder>

Page 18: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.18

Example of attributes and a body

<order> <item productCode=“456-CS”><description>computer model 1234 </description><quantity3</quantity><price>1234.78</price>

</item></order>

Information in an attribute

Information in body of element

Page 19: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.19

Structure of an XML document

Formally, an XML document consists of:

• an optional Prolog, and• a Root element (only one per document)

Prolog - includes instructions to specify how to process the XML document, Identified by construct <? ... ?>

Example: <?xml version="1.0" encoding="UTF-8"?>

identifies document as an XML document.

Root element - contains contents of document

Page 20: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.20

Namespace Mechanism

A mechanism of separating and identifying elements of the same name.

Widely used.

Particularly addresses problem of combining XML documents, if different documents use the same tag names to mean different things.

Page 21: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.21

Namespace identifier

• Tags combined with an additional namespace identifier to qualify it.

• Namespace identifier uses URI’s (Uniform Resource Identifiers) - Web naming mechanism.

• URLs are a subset of URIs, and would typically be used.

• URI/URL need not actually exist.

Page 22: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.22

Associating namespace identifier with local name

Suppose we wish to use URL:

http://www.cs.uncc.edu/~abw/ns

as the namespace to be referred to by prefix myNS.

Attribute in element is given as:

xmlns:myNS=“http://www.cs.uncc.edu/~abw/ns”

Page 23: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.23

Using namespaceSuppose whole purchase order document earlier is to use prefix myNS, document would have form:

<myNS:purchaseOrder id="53912" submitted="2004-08-05“

xmlns:myNS=“http://www.cs.uncc.edu/~abw/ns”>

<myNS:billTo>

<myNS:name>Department of Computer

Science</myNS:name>

.

</myNS:billTo>

.

</myNS:purchaseOrder>

i.e. every tag would have the namespace prefix.

Page 24: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.24

Namespace can be applied to every tag automatically if that is required without having to write a prefix, by using the attribute:

xmlns =“http://www.cs.uncc.edu/~abw/ns”

Using namespace throughout document without prefixes

Page 25: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.25

Now document would have form:

<purchaseOrder id="53912" submitted="2004-08-05“

xmlns=“http://www.cs.uncc.edu/~abw/ns”>

<billTo>

<name>Department of Computer Science</name>

.

</billTo>

.

</purchaseOrder>

i.e. every tag would have the namespace given.

Name space given by the xmlns tag becomes default namespace unless overridden by a prefix.

Page 26: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.26

XML Tags

• So far, not said what tag names and attribute names are legal in a document and how the tags are associated with a particular meaning and use.

• Name of tags and meaning need to be defined, just as variables given names in programs.

• As in programming languages, there are restrictions. Tags must start with a letter and are case sensitive.

Page 27: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.27

XML Schema

• A very flexible way of handing legal tag (element) names and defining structure.

• An XML document with required definitions.

Page 28: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.28

Question

If tags and structure are defined in an XML document, how does one define the tags and structure in the schema XML document?

Answer

We use the Schema Definition Language (XSD) which has defined tags and structure.

Includes data types.

Page 29: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

Schema for Purchase Order(First part)

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

<xsd:complexType name="PurchaseOrderType">

<xsd:sequence>

<xsd:element name="billTo" type="Address"/>

<xsd:element name="shipTo" type="Address"/>

<xsd:element name="items" type="Items"/>

</xsd:sequence>

<xsd:attribute name="id" type="xsd:string"/>

<xsd:attribute name="date" type="xsd:date"/>

</xsd:complexType>

2a.29

Page 30: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

Schema for Purchase Order(second part)

<xsd:complexType name="Address">

<xsd:sequence>

<xsd:element name="name" type="xsd:string"/>

<xsd:element name="company" type="xsd:string"/>

<xsd:element name="street" type="xsd:string"/>

<xsd:element name="city" type="xsd:string"/>

<xsd:element name="state" type="xsd:string"/>

<xsd:element name="postalCode" type="xsd:string"/>

<xsd:element name="country" type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

2a.30

Page 31: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

Schema for Purchase Order(final part)

<xsd:complexType name="Items">

<xsd:sequence>

<xsd:element name="item" minOccurs="0" maxOccurs="unbounded">

<xsd:complexType>

<xsd:sequence>

<xsd:element name="description" type="xsd:string"/>

<xsd:element name="quantity" type="xsd:positiveInteger"/>

<xsd:element name="price" type="xsd:decimal"/>

</xsd:sequence>

<xsd:attribute name="productCode" type="xsd:string" use="required"/>

</xsd:complexType>

</xsd:element>

</xsd:sequence>

</xsd:complexType>

</xsd:schema> 2a.31

Page 32: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.32

Sample XML document - A purchase order

<purchaseOrder id=“53912” date=“2004-08-05”><billTo>

<name>Department of Computer Science</name><company>University of North Carolina at Charlotte</company><street> 9201 University City Blvd.</street><city>Charlotte</city><state>NC</state><postalCode>28223</postalCode>

</billTo><shipTo>

<name>Department of Computer Science</name><company> University of North Carolina at Charlotte </company><street>9201 University City Blvd.</street><city>Charlotte</city><state>NC</state><postalCode>28223</postalCode>

</shipTo><items> <item productCode=“456-CS”>

<description>computer model 1234 </description><quantity>3</quantity><price>1234.78</price>

</item></items></purchaseOrder>

Page 33: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.33

XML schema

Document

xlns:xsi=“http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation=“ .. “

Associating a Schema with an instance of an XML document

Page 34: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.34

schema for the particular XML document, written in XSD “language”

XML document written in particular schema (particular XML language

Definition of XSD

Uses

Uses

Other schemas

Other Documents in other XML languages

Structure of documents

Page 35: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.35

Schema validation• Schema approach allows documents that are

supposed to conform to XML syntax and a specific schema to be checked against schema, prior to processing.

Two formal aspects

• Well-formedness – document conforms to rules of XML syntax.

• Validity – checks structure and identity of elements etc. that document should have from that schema.

Page 36: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.36

What XML gives you• A way of describing things which can be read

by computer.

• Used in Web services to describe the service interface, how to deploy it, etc, (in separate XML documents.

• Used in the job description document to describe a job being submitted (next set of slides)

Page 37: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.37

Sample XML documents found in the assignments

Page 38: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.38

Job description XML document(Resource specification language, 2 RSL-2/

Job Description Document JDD)

<?xml version="1.0" encoding="UTF-8"?><job>

<executable>/bin/echo</executable><directory>${GLOBUS_USER_HOME}</directory><argument>abc</argument><environment>

<name>GLOBUS_DUROC_SUBJOB_INDEX</name><value>0</value>

</environment><stdout>${GLOBUS_USER_HOME}/stdout</stdout><stderr>${GLOBUS_USER_HOME}/stderr</stderr><count>1</count><jobType>multiple</jobType>

</job>

Page 39: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.39

Web service deployment descriptor file WSDD language

<?xml version="1.0" encoding="UTF-8"?><deployment name="defaultServerConfig"

xmlns="http://xml.apache.org/axis/wsdd/"xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"xmlns:xsd="http://www.w3.org/2001/XMLSchema">

 <service name="examples/core/first/MathService" provider="Handler“

use="literal" style="document"><parameter name="className“ value=

"org.globus.examples.services.core.first.impl.MathService"/>

<wsdlFile>share/schema/examples/MathService_instance/Math_service.wsdl</wsdlFile>

<parameter name="allowedMethods" value="*"/><parameter name="handlerClass"

value="org.globus.axis.providers.RPCProvider"/><parameter name="scope" value="Application"/><parameter name="providers" value="GetRPProvider"/><parameter name="loadOnStartup" value="true"/>

</service></deployment>

Page 40: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.40

Web service description file (First part)WSDL language

<?xml version="1.0" encoding="UTF-8"?>

<definitions name="MathService" targetNamespace="http://www.globus.org/namespaces/examples/core/MathService_instance"

xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.globus.org/namespaces/examples/core/MathService_instance"

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

xmlns:wsrpw="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl" xmlns:wsdlpp="http://www.globus.org/namespaces/2004/10/WSDLPreprocessor"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

Page 41: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.41

Last part<portType name="MathPortType"

wsdlpp:extends="wsrpw:GetResourceProperty"wsrp:ResourceProperties="tns:MathResourceProperties">

  <operation name="add"><input message="tns:AddInputMessage"/><output message="tns:AddOutputMessage"/>

</operation> 

<operation name="subtract"><input message="tns:SubtractInputMessage"/><output message="tns:SubtractOutputMessage"/>

</operation> 

<operation name="getValueRP"><input message="tns:GetValueRPInputMessage"/><output

message="tns:GetValueRPOutputMessage"/></operation>

</portType></definitions>

Namespace

These names defined earlier in document

Page 42: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.42

Quiz

1. How are tags defined in HTML?

Answer

Page 43: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.43

Quiz

2. How are tags defined in XML?

Answer

Page 44: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.44

Quiz

3. A pair of XML tags with empty contents:

<tag_name></tag_name>can be written as

<tag_name/>

Under what circumstances would such a construction make sense?

Answer

Page 45: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.45

Multiple choice QuizSimilar to WebCT quizzes

What is an XML schema?

(a) A way to make XML documents secure

(b) A way of defining XML tags

(c) A way of encoding data for transmission

(d) None of the other answers

Page 46: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.46

Reference Books

Several books on XML, e.g.:

“Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, 2nd edition”

by S. Graham et al, SAMS publishing, 2004

Very good but 792 pages!!

Page 47: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.47

Additional XML materialsOn-line materials

• W3C consortium home page:

http://www.w3.org/XML/

• W3Schools XML Tutorial :

http://www.w3schools.com/xml/

Page 48: 2a.1 A review of the XML mark-up language Copyright B. Wilkinson, 2008. This material is the property of Professor Barry Wilkinson (UNC-Charlotte) and

2a.48

Questions