Adobe
產品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
更多產品
解決方案
數位行銷
數位媒體
教育機構
金融服務業
政府機關
網頁體驗管理
更多解決方案
教學 說明 下載 公司
購買
家庭使用 適用於個人和家庭辦公室
授權方案 適用於企業、學校和政府機關
其他購買方式
搜尋
 
資訊 登入
歡迎, 我的購物車 我的貨品 我的客戶支援
我的帳戶
登出
為何要登入?登入即可管理您的帳戶並取得試用下載、產品擴充功能、社群討論區等。
Adobe
產品 產業 購買   搜尋  
解決方案 公司
說明 學習資源
登入 登出 我的貨品 我的客戶支援
Date Date
Qty:
Subtotal
Checkout
開發人員中心 / Dreamweaver 開發人員中心 /

XML in the real world

作者 Scott Fegette

Scott Fegette

Modified

13 February 2005

頁面工具

在 Facebook 上共用
在 Twitter 上共用
在 LinkedIn 上共用
書籤
列印

Tags

系統需求

使用者等級

全部

Note: This article was written for Dreamweaver 8. However, the content in general is still valid.

You may have been recently introduced to XML in a variety of ways, so it can often be difficult to glean the most relevant information quickly as to how the language can be applied to your own projects and workflows. Although there's plenty of material available online to help you learn the basics of XML, I'd like to take a step back and look at what XML is—and is not—and how it's used in a wide range of applications from consumer to developer.

As connected applications take a greater foothold in the marketplace, and standard means of communicating between them are required, XML will play a key role in brokering this information exchange. In some ways, the revolution has already silently taken hold. Let's take a look.

What Is XML?

At its core, XML (eXtensible Markup Language) represents a standardized framework for defining markup languages, along with an associated set of generic tools for processing XML-based documents. It's a way for you to define structured information of all kinds—content, object data, inter-application messages, or syndicated content summaries.

RSS (Really Simple Syndication), arguably the most popular content syndication format on the web today, is simply an XML-based schema. XHTML is essentially the HTML markup language you're well familiar with—only adjusted to conform to XML structure, syntax, and validation. So it is yet another XML-based language. WML is the XML-based markup for WAP services. The list goes on. By being built upon XML, these case-specific schemas have inherited XML's rich infrastructure for free. No complaints here!

Outside of the many structured language implementations of XML, the most obvious role of XML as a stand-alone "file format" is to represent data apart from visual markup. But why would you want to store content in XML as opposed to a database? To one point of view, XML is a more neutral and accessible container for your data to reside within—one that does not require as much database adapters and local configuration. Although it's also common to find XML used as streamed data from a connected application—that is, as an environment-neutral communications vehicle—XML content is designed to be equally effective stored as a flat file.

This flexibility opens up many possibilities, but it also has its drawbacks. For example, parsing and processing an XML file can become cumbersome quickly when you encounter very large documents and datasets, whereas native database drivers are highly efficient at parsing and processing large volumes of data. The AJAX development model is based on sending XML data back and forth between browser and server, allowing JavaScript to use the received data to update a web page without refreshing. Flash-based Rich Internet Applications can, of course, directly access XML files and streams by way of the XML class and connector component in Flash 8. In ActionScript 3, XML is now treated as a native data type. As opposed to opening and reading an XML file, and then parsing and acting upon it, ActionScript 3 allows you simply to refer to an XML file as a variable (or load one remotely), and manipulate your data directly from that point on. You can expect to see more and more coding environments and frameworks move this way as XML entrenches itself further as data's lingua franca of the web.

XML is very effective at providing aggregate views of content, such as syndicating a range of documents. RSS is one format widely used for syndication, and in most cases is autogenerated by the system managing the site content. Web log frameworks like Movable Type and Blogger generate and update a static RSS file on your server whenever a new post is published to the system, which RSS-savvy clients can then read and use (in most cases an internal stylesheet) to create the visual layout of the structured content data in the RSS/XML feed. Here XML is not serving as a replacement for a database but as a specific view upon the data within that can be read and processed by a much wider variety of clients than a fixed web application.

As I noted earlier, if XML has become the standard for representation of web-based information, then you would need some way both to make the more generic XML data appear itself as other XML-based documents, and visually format the information for web browsers, mobile phones, and so on. XML transformation allows you to define rules that convert one class of XML document into another, and by using generic XML tools (XSLT, XQuery, and XPath) you can build reasonably complex aggregate views of your content.

Structure of a Well-Formed XML Document

The structure of an XML document is hierarchical in fashion—a labeled and ordered tree of data. The nodes of this tree largely fall into one of two types: character data (or CDATA) nodes that contain text strings and element data nodes that correspond to the structured data of your document. The element data nodes consist of both a name for the element's data type and a set of attributes that relate to that element type.

Take an <img> tag, for example, which contains several properties that further define it: height, width, alt text, border size, and so on. There are other types of nodes and elements in XML trees such as comment nodes, instructions for processing the document, and (probably most importantly) the schema to which your document subscribes. The schema lets consumers of the document know both how it's to be parsed and what constitutes its validity.

As opposed to HTML, which—despite being a markup language itself—has a somewhat lax structure, XML is a much stricter environment and requires its documents be well-formed. So although you may not use XML directly in practice today, it's important to at least become comfortable with its conventions and start writing well-formed code early on.

The actual structure of an XML document is straightforward. The following XML document is the data representation of a message from Jane to John:

<?xml version="1.0" encoding="ISO-8859-1"?> <message> <from>Jane Doe</from> <to>John Doe</to> <date>February 14, 2006</date> <body>Are the annual report files finished yet?</body> <priority>high</priority> <attachments> <attachment type="jpg">http://intranet.foo.com/files/file_1.jpg</attachment> <attachment type="pdf">http://intranet.foo.com/files/file_2.pdf</attachment> </attachments> </message> </xml>

Note first that this (and each well-formed) XML document starts with an XML declaration that defines both the XML version and character encoding used within the document itself. The root node of this particular document is message—wholly appropriate given its content—and that message can contain several properties:

  • from: The sender of the message
  • to: The recipient of the message
  • date: When the message was sent
  • body: The main content of the message
  • priority: High, medium, or low
  • attachments: A container tag that can encapsulate a number of attachment tags pointing to specific files
  • attachment: A tag that defines each unique file associated with the message

Syntax-wise, XML is both very strict in its interpretation, while reasonably easy to learn and use. Here are a few guiding principles:

  • XML tags are case-sensitive
  • XML elements must be nested appropriately, and have a closing tag
  • All XML documents must have a single root element
  • Attributes in XML documents must be quoted
  • XML comments follow the same syntax as HTML comments (<!-- comment -->)

In a nutshell, an XML file is simply a text file that wraps data into logical constructs. How those constructs are parsed is another matter. XML schemas (representing classes of documents like an RSS feed or WML deck) are the current model for describing the structure of information within a class of XML documents, defining the constraints that a particular XML-based language or implementation follows and the structure of the data encapsulated within. Without a schema, machine validation has no larger context to determine whether your data structure is valid, or translate that data into other forms.

As you can see, XML not only lays out its data in a very clear, structured format, but it's also incredibly verbose and self-explanatory to the various clients and applications that may access it.

How Is XML Used Today?

A good example of how XML can be used as a clean content model in a shipping product today is the new (and relatively unearthed) XSLT Transform feature in Dreamweaver 8. You can read through a more detailed overview of this in my blog posting, FOTD 22: Dreamweaver 8 – XSLT Authoring. A site could be easily constructed by combining an XML document that holds the content data (your page text, perhaps pointers to specific image files and their dimensions, site navigation, headers/footers, and so on) and an XSL (eXtensible Stylesheet Language) document in conjunction with a CSS style sheet that defines how the page is visually constructed.

Why is this important? By separating your content from your data, you have the ability to work on each without affecting the other. For example, content teams could be updating the XML content and image pointers in the XML file at the same time that visual designers are tweaking the CSS style sheet (visual layout) and an integration engineer is fine-tuning the XSL document that pulls it all together. No collisions by three parties trying to check out or open the same HTML file at the same time. Development harmony achieved.

Earlier in this article, I stated that RSS feeds are one of the most popular XML-based schemas in practice today. It's become very common to see the XML icons alongside content in popular news and content sites these days, pointing to syndicated summaries of new and updated content. More and more web-based applications like Google's Gmail and the social bookmarking site del.icio.us allow you to receive RSS-based summary information whenever new e-mail reaches your account, or new bookmarks in your subscriptions are entered.

The new XSLT transformation feature in Dreamweaver 8 is one of the first front-end design applications to really dig into the depth of XML and the resulting flexibility when transforming that XML into an XHTML-based representation for browsers. Although you can read more about it in my blog posting, the feature essentially allows you to access the hierarchical structure of a local or remote XML source and manipulate it much as you would a database query.

Besides autogenerating the XSL file for your transform, Dreamweaver provides a front end to the generic XML utility, XPath, which can allow you to build conditional logic into your transformation by pulling out specific elements from an XML file and acting on them. With the combination of an XML data source, XPath queries to find content-specific data within that XML source, XSLT to help transform that content into browser-readable XHTML, and a CSS style sheet to add the visual look and feel to it, you can build a web page (and website) without a single HTML file in view. Very cool.

Furthermore, many traditional desktop-based applications are starting to embrace XML in a number of ways. The Apple Mac OS X operating system makes use of XML-based PLIST files to store application preferences and data. The file formats in Microsoft Office are now based on XML. New hybrid connected applications like the Delicious Monster Library manage datasets in XML and let you publish your data easily.

With the ubiquity of a flexible content markup environment like XML, it makes less and less sense to bury data in proprietary formats, and more and more sense to standardize the data and let the applications—whether web-based, device-based, service-oriented, or desktop-based—handle the rest.

Where to Go from Here

I hope this article has broadened your perspective of XML and given you a high-level overview of the need it fills in the next-generation, Web 2.0 world of connected applications and content. But I also hope it has provided some ideas as to how you can start considering XML in future projects, and as solutions to the problems you face today.

It's not a leap of faith to say that you can expect to see more and more data exchange implementations move towards XML-based solutions in the future. So if you've been putting off learning more about XML, now's the time!

More Like This

  • Exchanging data using the Spry framework for Ajax and PHP
  • Beginner's guide to databases
  • Marking up your site for easier redesign in five steps
  • SQL primer for Dreamweaver users
  • Using Subversion with Dreamweaver CS5 – Part 1: Introducing Subversion
  • Creating dynamic tables with the Spry framework
  • Using Subversion with Adobe Dreamweaver CS5 – Part 2: Configuring Dreamweaver to use Subversion
  • Using Subversion with Dreamweaver CS5 – Part 3: Configuring Apache with Subversion support
  • Editing a WordPress theme with Dreamweaver CS5 – Part 1: Learning the basics
  • Editing a WordPress theme with Dreamweaver CS5 – Part 2: Setting up your site

產品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • 行動應用程式
  • Photoshop
  • Touch Apps

解決方案

  • 數位行銷
  • 數位媒體
  • 網頁體驗管理

產業

  • 教育機構
  • 金融服務業
  • 政府機關

說明

  • 產品說明中心
  • 訂購與退貨
  • 下載與安裝
  • 我的 Adobe

學習資源

  • Adobe Developer Connection
  • Adobe TV
  • 培訓與認證
  • 論壇
  • 設計中心

購買方式

  • 適用於個人和家庭辦公室
  • 授權方案
  • 其他購買方式

下載

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

公司

  • 新聞室
  • 合作夥伴方案
  • 企業社會責任
  • 工作機會
  • 投資者關係
  • 事件
  • 法律聲明
  • 安全性
  • 聯絡 Adobe
選擇您所在的國家/地區 台灣 (變更)
選擇您所在的國家/地區 關閉

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

使用條款 | 隱私權政策和 Cookies (更新)