CMWEB 250 Mark DuBois – [email protected]@icc.edu.

24
CMWEB 250 CMWEB 250 Mark DuBois – [email protected]

Transcript of CMWEB 250 Mark DuBois – [email protected]@icc.edu.

Page 1: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

CMWEB 250CMWEB 250

Mark DuBois – [email protected]

Page 2: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

XML FundamentalsXML Fundamentals

Extensible Markup Language Based on SGML – deemed to complex for

mere mortals XHTML is based on XML

Characteristics Well formed Valid

What is so special about XML?

Page 3: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

StandardsStandards

XML is extensible (be definition) In order for it to be useful, everyone

must agree upon standards For example, you can validate RSS feeds

just as you can validate XHTML http://feedvalidator.org/ is an example We will cover RSS and podcasts later in the

course

Page 4: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

OHIO PrincipleOHIO Principle

Ray Ozzie (MS) Only handle information once Consider this example -

http://faculty.icc.edu/mdubois/xml/tutorials/CITRIX/ (tutorial dealing with use of our Virtual Lab environment)

Single XML file used to create PDF file (in typical letter format) PDF file (in A4 format for students in Europe and Asia - yes, we have

some in various classes) HTML file (for reading online in your browser) ZIP file (in the event you want to keep a copy of this tutorial and

display it locally in your browser) If you find a typo, you will find it in every one of these documents If I correct the typo, I run one XML file through a program

(transformation) and generate new versions of all above files This is power of XML (and XSL-T – transformations)

Page 5: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

XML UsageXML Usage

Can create Custom tags (can contain custom attributes)

Need to agree upon standardization (DTDs and Schemas) – one example is RSS

Much more than just web interface, markup language with promise of cross platform, long term data format

Once data is encoded you can manipulate in any number of ways (example of tutorials we just discussed)

Page 6: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Name.xml exampleName.xml example

Examine topic 2 examples link in Moodle Open this file in Internet Explorer Note when you display the name.xml

document you can collapse/ expand the element by clicking on the + or - symbol to the left of the beginning tag of the element

This is controlled by XSL style sheet (I also provide a link to that so you can see the details). This is included in the browser when the XML parser is installed.

Page 7: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Uses for XMLUses for XML

Lots of examples Podcasts Dreamweaver interface MS-Office (2007) Many web sites use XML data stores Tutorials I mentioned earlier

Page 8: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Ok, so what is XMLOk, so what is XML Looks like HTML (sort of)

Tags <title> Elements <title>Mark</title> Attributes <title greeting="Mr.">

Parsed by browser (or other application) HTML is about presentation, XML is about data We currently try to separate presentation from content/

data XHTML is a stopgap approach to achieve this (think of it as

HTML that must follow XML rules) XHTML document can directly contain XML document XML document can directly contain XHTML document

One big advantage is that XML documents can be displayed/ processed by any XML parser - so your data is a lot more interchangeable

FYI - the extensible part means that you can create your own custom tags and custom attributes That is the good news That is also the bad news

Page 9: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

XML structureXML structure

Like XHTML, there is a DOM Problem - you can create custom tags (not true in

XHTML) How do you navigate in XML? XPath is one

approach Think of the document as a tree with branches -

see page 15 Elements can contain only elements (no text) and are said

to have Element content Elements can contain text (no elements) and are said to

have Simple content Elements can have both elements and text and are said to

have Mixed content

Page 10: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Task 1Task 1

Build a simple XML document in Notepad (or Altova XMLSpy if you are in class)

If you need an idea, consider an address book or a catalog of books in a library

We will do part of this as a group so everyone is comfortable with the interface (for those in the traditional class)

If you do not have XMLSpy, use Notepad or Cooktop (http://www.xmlcooktop.com/).

Page 11: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Well formed XMLWell formed XML

Examine data process and hierarchy on pages 26 and 27 of textbook

First, examine Order.XML (open in IE) Note specific structure that document

follows Empty elements may be displayed as

<Address2 />

Page 12: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Rules for ElementsRules for Elements

Every tag that starts must end (or be self closing) Elements must be properly nested

<em><strong>Text</strong></em> There can only be one root element Must obey XML naming conventions

Start with letter or hyphen (not number or special characters)

Numbers, hyphens, periods allowed after first character No spaces and no space after < when begin tag No colon (:) - used for namespaces Don't start with xml (in combination of upper or lower

case) - reserved Case sensitive - be consistent Whitespace will be retained (except for end of line

whitespace - CF LF)

Page 13: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Rules for attributesRules for attributes

Same as for elements Attributes are unordered - <title salutation="Mr."

e-Mail="no">... Must be in quotes (either single or double will

work - be consistent) Be careful of data that contains names with apostrophes -

O' Conner, for example Examine Order2.xml to see attributes included Text has whole section on attributes vs. elements

- pages 43 - 44 So, which should one use? I will add my 2 cents here as well

Page 14: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

CommentsComments

Just like XHTML <!-- comments here --> Order3.xml contains some Hey, we are talking about data. When

was the last time you wanted to put comments into the data?

Page 15: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

XML PrologueXML Prologue

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

Including this can cause some browsers (like IE) to operate in Quirks mode I don't name them, it means it behaves oddly and doesn't

always process the document as expected If you include, version is required, other attributes are

optional If you include all, version, encoding, standalone must

appear in that order Idea for encoding is for all to be Unicode - UTF-16 - to

handle all languages Ended up with a lost of others (windows-1252, ISO-8859-1 and

so forth) Order4.xml demonstrates this

Page 16: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

EntitiesEntities

If your data includes special characters (like &) you will run into problems

Get around this by escaping characters There are 5 in XML - you can define others with a

DTD, but these are it for now &amp; - & &lt; - < &gt; - > &apos; - ' &quot; - "

Might be familiar with &nbsp; from XHTML - this won't work

Page 17: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Namespaces IntroductionNamespaces Introduction

When we started this class, we made some fundamental assumptions I probably greeted those in the traditional

class by saying “welcome” (or something similar)

We just established a namespace In this case, we agreed that we would be using

English to communicate. Had I said “hola” or “bon soir” we might be

using a different namespace

Page 18: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

NamespacesNamespaces Consider that I want to have part of one XML document included into some XHTML Consider that I have a <title> tag in the XML which means the title of the person

Of course, there is also a <title> tag in XHTML for the title of the document Consider that I also have some furniture described in the XML document and one of the tags is

called <table> Of course, this conflicts with the <table> tag in XHTML

What to do? That is why we have namespaces We can specify which tag should be processed by which parser by using a prefix to reference a

namespace. But, we must also be able to communicate throughout the world. Which is why we have URI, URL

and URN Examine default MS XSL document to see example of URN and URI in namespaces

Lets examine Namespace.xml Note the use of two prefixes to separate which tag is evaluated/ processed

Can also use a default namespace by specifying xmlns without a prefix Example Namespace2.xml

Can also declare namespaces on child elements Namespace3.xml is an example

If you needed to cancel a namespace (and not point to another) <name xmlns="">Whatever</name>

Does it matter which approach? As a general rule, no, note page 79 in your book to see minor differences. Most applications will process this in the same way

Page 19: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

When to use namespacesWhen to use namespaces

If the only documents you ever create will only be used by you, don't

If you are only using documents in one company and have absolute control over tag names, don't

If you exchange data between companies and do not have complete control over all tag names (or you need to include snippets into XHTML documents), you really have no choice.

Page 20: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Review CooktopReview Cooktop

Quick overview of the use of this tool Can complete many labs without the use of

XMLSpy Per our license agreement, it can only be

used in the classroom itself (not the virtual lab) and on my instructor laptop

Page 21: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Review XMLSpyReview XMLSpy

For those in class, we have capability of using this tool Brief review of the use of this tool

Page 22: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Lab 1 OverviewLab 1 Overview

Create well formed XML document Follow base rules Display in Internet Explorer If able to open and expand (+) or contract

(-) document, it is well formed Submit via Moodle as zip file

Use results of task 1 (address book) as a starting point (do not use address book, be more creative)

Page 23: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

SummarySummary

Reviewed basics of well formed XML documents

Please provide feedback as to your level of understanding (choices)

Lab 1 reviewed briefly (should be easy to complete)

One thing to remember – XML documents must be well formed

Page 24: CMWEB 250 Mark DuBois – mdubois@icc.edumdubois@icc.edu.

Muddiest pointMuddiest point

For those in class On 3 x 5 card

What did you find unclear tonight? What item was most confusing?