16
Tutorial: Introduction to XML Presented by IBM’s developerWorks 1 Tutorial: Introduction to XML Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July, 1999 About this Tutorial XML, the Extensible Markup Language, has been hailed as a technical revolution comparable in scope to sliced bread and the wheel. This tutorial cuts through the hype to show you what XML is all about. XML is an important new technology that will revolutionize the web. Just as important, XML isn't rocket science. There's no reason you can't start using XML to transform your business today. About the Author Doug Tidwell is a Senior Programmer at IBM. He has well over a tenth of a century of programming experience and has been working with XML-like applications for several years. His job as a Cyber Evangelist is to help customers evaluate and implement XML technology. He holds, with special gloves, a Masters Degree in Computer Science from Vanderbilt University and a Bachelors Degree in English from the University of Georgia.

Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Tutorial: Introduction to XML Presented by IBM’s developerWorks 1

Tutorial: Introduction to XMLDoug TidwellCyber Evangelist, XML developerWorks TeamRaleigh, NCJuly, 1999

About this TutorialXML, the Extensible Markup Language, has been hailed as a technical revolution comparable in scope tosliced bread and the wheel. This tutorial cuts through the hype to show you what XML is all about. XML isan important new technology that will revolutionize the web. Just as important, XML isn't rocket science.There's no reason you can't start using XML to transform your business today.

About the AuthorDoug Tidwell is a Senior Programmer at IBM. He has well over a tenth of a century of programmingexperience and has been working with XML-like applications for several years. His job as a CyberEvangelist is to help customers evaluate and implement XML technology. He holds, with special gloves, aMasters Degree in Computer Science from Vanderbilt University and a Bachelors Degree in English fromthe University of Georgia.

Page 2: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 1 - What is XML? www.ibm.com/developerWorks

2 Presented by IBM’s developerWorks Tutorial – Introduction to XML

Section 1 - What is XML?

What is XML?

Extensible Markup Language, or XML for short, is anew technology for web applications. XML is aWorld Wide Web Consortium standard that lets youcreate your own tags. XML simplifies business-to-business transactions on the web.

Why Do We Need XML?

Why do we need XML when everyone's browsersupports HTML today? To answer this question,look at the sample HTML Code shown. HTML tagsare for browsing; they're meant for interactionsbetween humans and computers.

Rendering HTML

When rendered, the HTML in the previous examplelooks like this. As you can see, HTML tags describehow something should render. They don't containany information about what the data is, they onlydescribe how it should look.

Page 3: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

www.ibm.com/developerWorks Section 1 - What is XML?

Tutorial: Introduction to XML Presented by IBM’s developerWorks 3

Sample XML Code

Now let's look at some sample XML Code. WithXML, you can understand the meaning of the tags.More importantly, a computer can understand themas well. It's easier for a computer to understandthat the tag <zipcode>34829</zipcode> is azip code.

Rendering XML

XML from the previous example might be renderedlike this. Notice that even though the tags aredifferent, they can still be rendered just like HTML.

A Second Rendering of XML

By applying a different stylesheet to the samedocument, an XML document can be rendered indifferent formats. The key is that with XML theinformation is in the document, while the renderinginstructions are elsewhere. In other words, contentand presentation are separate.

Page 4: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 1 - What is XML? www.ibm.com/developerWorks

4 Presented by IBM’s developerWorks Tutorial – Introduction to XML

How XML Will Change the Web

XML applications provide many advantages. Let'stalk about several of those now.XML's strongest point is its ability to do datainterchange. Because different organizations (oreven different parts of the same organization)rarely standardize on a single set of tools, it takes asignificant amount of work for two groups tocommunicate. XML makes it easy to sendstructured data across the web so that nothing getslost in translation.

Enable Business to Business Communication

When using XML, I can receive XML-tagged datafrom your system, and you can receive XML-tagged data from mine. Neither of us has to knowhow the other's system is organized. If anotherpartner or supplier teams up with my organization, Idon't have to write code to exchange data with theirsystem. I simply require them to follow thedocument rules defined in the DTD.

Enable Smart Agents

When writing an agent, one of the challenges is tomake sense of incoming data. A good agentinterprets information intelligently, then responds toit accordingly. If the data sent to an agent isstructured with XML, it's much easier for the agentto understand exactly what the data means andhow it relates to other pieces of data it may alreadyknow.

Page 5: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

www.ibm.com/developerWorks Section 1 - What is XML?

Tutorial: Introduction to XML Presented by IBM’s developerWorks 5

Enable Smart Searches

One major problem with today's web is that searchengines can't process HTML intelligently. Forexample, if you search on "chip" when you'relooking for someone named Chip, you might getpages on chocolate chips, computer chips, andguys named Chip. But if there were a DTD forname and address records, searching for a guynamed Chip could generate much more accurateand useful search results.

Summary

So why do we need XML? XML makes it easier fortwo computers to exchange data with each other.Your data is described using tags that describewhat each piece of data is. XML doesn't replaceHTML, though; they're designed for differentpurposes. XML is the Web's language for datainterchange and HTML is the Web's language forrendering.

Review

Let's review. When is it appropriate to use XML?

A. When I want to display something in a browser.

B. When I feel like creating my own tags.

C. When I want to add a buzzword to my resume.

D. When I need to send self-describing data toanother machine or application.

[The correct answer is D.]

Page 6: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 2 – How can I use XML today? www.ibm.com/developerWorks

6 Presented by IBM’s developerWorks Tutorial – Introduction to XML

Section 2 – How can I use XML today?

Accessing XML on the Client

XML changes the way data moves acrossnetworks. XML encapsulates data inside customtags that carry semantic information about the data.A common question is, "Once I've got some XML-tagged data, how do I view it?"

IBM Solutions

The answer to that question is the focus of thistopic. IBM has solutions that let you view XML dataon any client or browser. IBM's technology allowsyou to take full advantage of the capabilities ofeach platform; you don't have to take a lowestcommon denominator approach. If your client orbrowser supports XML or Dynamic HTML, you canuse those features, while still generating usefulviews of your XML-tagged data for low-functionclients.

The XML Enabler

One IBM solution for doing this is the XML Enabler,available on IBM's alphaWorks site. It allows you toconvert XML-tagged data into HTML, usingdifferent style sheets for different browsers. We'lldiscuss the XML Enabler briefly, then we'll showyou how to view XML-tagged data on any browseryou choose.

Page 7: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

www.ibm.com/developerWorks Section 2 – How can I use XML today?

Tutorial: Introduction to XML Presented by IBM’s developerWorks 7

The XML Enabler

The architecture of the XML Enabler is simple.When a browser attempts to load an XMLdocument, the XML Enabler looks at the type ofbrowser that requested the document. The XMLEnabler then selects a stylesheet written in theExtensible Stylesheet Language, or XSL, based onthe browser type.

The XML Enabler

The XML Enabler retrieves the requested XMLdocument, processes it with the appropriatestylesheet, and returns the results to the browser.This allows you to generate different views of anXML document, and each view takes advantage ofas many browser features as possible.

Implementation

The XML Enabler is implemented as a Java servlet.It is built on the XML4J parser from IBM and theLotus XSL Processor, both of which are availableon IBM's alphaWorks site. All of the code is writtenin Java, so it's platform independent.

Page 8: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 2 – How can I use XML today? www.ibm.com/developerWorks

8 Presented by IBM’s developerWorks Tutorial – Introduction to XML

A Sample XML Document

Before we demonstrate viewing XML on variousclients, let's look at a sample XML document. Oursample document is a news item containing a title,a summary, a category, and other pieces ofinformation.

A Rendered XML Document

These two screen captures illustrate the range ofbrowsers the XML Enabler can support. In thebackground, Microsoft's Internet Explorer Version 5renders an XML document using an XSLstylesheet. In the foreground, a palmtop browserrenders an HTML version of the same XMLdocument. The XML Enabler determines what kindof document is delivered to each browser.

alphaWorks and developerWorks

IBM's alphaWorks site atwww.alphaWorks.ibm.com contains many XML-related tools and technologies, including parsers,editors, and stylesheet processors.

In addition, the XML Zone of IBM's developerWorkssite, www.ibm.com/developer, contains severalprogramming tutorials related to XML.

Page 9: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

www.ibm.com/developerWorks

Tutorial: Introduction to XML Presented by IBM’s developerWorks 9

Summary

In summary, the XML Enabler allows you to beginworking with XML technology today. You can serveXML-tagged data to any type of client withouthaving to change your existing systems orbrowsers. If your users have modern browsers, youcan create XSL stylesheets that use their latestfeatures. At the same time, you can support userswith lower-function browsers. Best of all, the XMLEnabler lets you do these things in a way that'seasy to support and expand as your environmentchanges.

Review

Let's review. From a business perspective, which ofthe following statements about XML is true?

A. There’s no point migrating to XML until yourwhole enterprise has installed Internet ExplorerV5.

B. We’ll migrate to XML when most of the majorbrowser vendors support it.

C. We can use XML documents here and there,but we’ll have to convert them to a single text-only view that all browsers can handle.

D. We can use XML today and transform our XMLdocuments so that any browser can renderthem attractively and usefully.

[The correct answer is D.]

Page 10: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 3 – Applying XML www.ibm.com/developerWorks

10 Presented by IBM’s developerWorks Tutorial – Introduction to XML

Section 3 – Applying XML

Introduction

In order to build XML applications, you will need todo four things:

• Select or write a DTD• Generate XML documents• Interpret XML documents, and• Display XML documents.

Selecting or Writing a DTD

What is a DTD? A document type definition defineswhat tags can go in your document, what tags cancontain other tags, the number and sequence ofthe tags, the attributes your tags can have, andoptionally, the values those attributes can have.

Generating an XML Document

Think of the DTD as a template you fill in. For eachelement, get the data from its location such as adatabase query, a full-text search, or a directoryquery, and then simply put it in the template.When the template is full (all the required elementsare filled in and the document is valid), you cansend it to the requestor of the document.

Page 11: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

www.ibm.com/developerWorks Section 3 – Applying XML

Tutorial: Introduction to XML Presented by IBM’s developerWorks 11

Tag Rules for XML Documents

There are a couple of rules for XML tags that aredifferent from HTML tags:

• XML tags can't overlap.<a><b></a></b> isn't allowed. If youstart a <b> tag inside an <a> tag, you haveto end it inside the <a> tag as well.

• You can't leave out any end tags. Tagslike </p> and </br> are required.

• Tags that don't contain any text cancontain the end marker at the end of thestart tag. In other words, <br></br> isequivalent to <br />.

Invalid, Well-Formed, and Valid Documents

There are three kinds of XML documents:

• Invalid Documents: Documents that don'tfollow the tag rules we just discussed. If adocument has a DTD, and it doesn't followthe rules defined in its DTD, that documentis invalid as well.

• Well-Formed Documents: Documentsthat follow the XML tag rules, but don'thave a DTD.

• Valid Documents: Documents that followboth the XML tag rules and the rulesdefined in their DTDs.

Interpreting XML Documents

When you need to interpret an XML document,there are two APIs you can use: The DocumentObject Model, or DOM, and the Simple API forXML, or SAX.

The DOM is a standard of the World Wide WebConsortium that creates a tree view of your XMLdocument. The DOM provides standard functionsfor manipulating the elements in your document.

Page 12: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 3 – Applying XML www.ibm.com/developerWorks

12 Presented by IBM’s developerWorks Tutorial – Introduction to XML

Interpreting XML Documents

The SAX API notifies you when certain eventshappen as it parses your document. When yourespond to an event, any data you don't specificallystore is discarded.

SAX or DOM?

Why would you use SAX or DOM? If yourdocument is very large, using SAX will savesignificant amounts of memory when compared tousing DOM. This is especially true if you only needa few elements in a large document. On the otherhand, the rich set of standard functions provided bythe DOM isn't available when you use SAX.

Displaying XML Documents

There are several ways you can display XMLdocuments. If your browser can display XML, youcan simply send the document out to the browser.Or use an XSL stylesheet to transform the XML intosomething your browser can handle. An XSLstylesheet contains some number of templates thatdefine how the elements in an XML documentshould be transformed.

Page 13: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

www.ibm.com/developerWorks Section 3 – Applying XML

Tutorial: Introduction to XML Presented by IBM’s developerWorks 13

Displaying XML Documents

If you want to do complicated sorting orrestructuring that's beyond the realm of XSL, useDOM. In this method, you parse the XMLdocument, then write Java code to manipulate theDOM tree in whatever way you wish. Your codehas complete access to the DOM and all of itsmethods, so you're not bound by the limitations ordesign decisions of XSL.

Review

We've covered a lot! Let's review. Which of thefollowing is not a way to display an XMLdocument?

A. Using the DOM.

B. Using an XML-capable browser.

C. Using expensive, proprietary software than canonly be bought from certain vendors.

D. Using XSL.

[The correct answer is C.]

Page 14: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 4 – Case Study www.ibm.com/developerWorks

14 Presented by IBM’s developerWorks Tutorial – Introduction to XML

Section 4 – Case Study

CEO Overview

Hello, my name is Amanda Reckonwith, presidentand CEO of Hard to Find Auto Parts, amultinational conglomerate. Our mission is toprovide our customers with high quality auto partsin a timely manner and at a fair price. The secret toour success is our ability to locate hard to find autoparts from our suppliers over the internet, as wellas our ability to show up as a parts source whenour customers conduct internet searches.

Turning to XML

Due to increasing competition in the marketplace,we must be able to find parts quickly and at thebest available price. We've turned to XML toconduct e-business within our marketplace. Wehave two simple choices. We can either conform toan emerging standard, and even help define it, orget left behind. Let's talk to John, our XMLdeveloper!

John, XML Developer

Hello, my name is John. I'm an XML applicationdeveloper here at Hard to Find Auto Parts. I'mresponsible for ensuring that we meet our businesschallenges. I'll describe to you our rationale forusing XML.

XML makes searches smarter. As an example,consider the extranet that we share with oursuppliers. When we need to search the extranet tofind a part, XML allows us to find exactly whatwe're looking for. We share a DTD with all of oursuppliers, so our searches return exactly whatwe're looking for.

Page 15: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

www.ibm.com/developerWorks Section 4 – Case Study

Tutorial: Introduction to XML Presented by IBM’s developerWorks 15

Make Searches Smarter

Before we used XML, our searches returnedthousands of hits, most of which were garbage. Ifwe looked for a window for a Honda Accord, wemight get a news article about the Middle EastPeace Accord. With an XML-based search, all ourresults are XML documents that contain a<model>Accord</model> tag.

Maintain Communications

The fact that we use XML to represent our data onthe Internet and within our extranet means that oursuppliers and customers are insulated from anychanges we might make to our infrastructure.We're insulated from any changes in their systemsas well. Because data interchange is one of XML'sstrengths, we're able to move data across differentsystems without losing anything in translation.

Smart Agents

Because all of our suppliers send data about theirinventory and prices in XML, we've been able towrite agents that process that data intelligently. Forexample, we have agents that watch certain autoparts in our inventory control system. When only afew of a particular item are in stock, our agentchecks with all our vendors to find out which onehas the part in stock and has the best price. UsingXML has given us a clear advantage over ourcompetitors.

Page 16: Tutorial: Introduction to XMLwritedoc.com/resume/projects/documents/other/eLearning/... · 2018. 3. 9. · Doug Tidwell Cyber Evangelist, XML developerWorks Team Raleigh, NC July,

Section 4 – Case Study www.ibm.com/developerWorks

16 Presented by IBM’s developerWorks Tutorial – Introduction to XML

Customer Recognition

As the leading XML-based auto parts dealer,information from our database turns up on XMLsearch engines all over the world. Customers whoare tired of bogus HTML searches can use ourXML-based approach to find exactly what they'relooking for. Auto parts houses that haven't caughton to XML don't have a chance to make a sale tothese customers.

Review

Ready for a review? Which of the following is notan advantage of using XML over standard markuplanguages?

A. Using XML provides us with the ability toconduct smarter searches.

B. Using XML provides better business tobusiness communication.

C. XML incorporates the use of agents thatprocess data intelligently.

D. XML tags are more difficult to learn thanstandard HTML or DHTML tags.

[The correct answer is D.]