What Is XML?


XML was born out of one simple observation: Exchanging data between different computer programs is a difficult task. All the systems attempting to share data have to speak the same "language." This starts getting really messy when different companies (who may even be rivals) build the programs. Don't forget that there are lots of different types of data that might need to be exchanged and that data can look very different. Stock exchange information doesn't exactly look a lot like baseball scores, does it?

XML gets around these problems by not actually defining the full language for data exchange. Instead, it just lays out the syntax for languages to be built from it (this is why it's called extensible! ). Superficially, XML looks a lot like HTML, as it should because they both have roots in a much older markup language, Standard Generalized Markup Language (SGML). If you know HTML, you already know quite a bit about XML ” opening and closing tags, tag attributes, and so on. However, there is quite a bit different between the two as well. XML is much more strict than HTML is. When working with XML, you have to be aware of some specific syntax rules:

  • All XML tags must be enclosed in angle brackets (< and >).

  • All XML tags must be closed.

  • XML is case-sensitive.

  • All attributes must be enclosed in quotes.

Another important difference between HTML and XML is that there are no "set" tags in XML. <flower></flower> is just as legitimate as <p></p> is. The XML document in Listing 23.1 clearly demonstrates both how similar and how different XML and HTML are. XML has tags, just like HTML, but the tags don't describe how the document will look ”they describe just its data.

Listing 23.1 This Is a Simple XML Document
 <plantList name="My List">      <perennial>                <variety>Rose</variety>          <commonName>Zepherine Drouhin</commonName>          <bloomColor>Deep Pink</bloomColor>          <light>Part Shade</light>      </perennial>      <perennial>          <variety>Delphineum</variety>          <commonName>Delphineum Independence</commonName>          <bloomColor>Deep Blue</bloomColor>          <light>Sun</light>      </perennial>  </plantList> 

But, I hear you arguing, how does XML actually do anything if anything can be a tag? As mentioned earlier, XML doesn't actually define any language. That role is left to you as a developer.

DTDs and XML Schemas

As a developer, you can create what is known as a Document Type Definition (DTD) or XML schema (a newer way of defining XML-based languages that was recently ratified by the Web standards body, the World Wide Web Consortium [W3C]). These documents define the actual tag set for a language. DTDs have their own special format. XML schemas actually use XML to define the tag set.

For example, there are a number of DTDs already in use for defining XML-based languages for news information, music, and DNA proteins . In fact, there is even a new version of HTML, XHTML, which is defined by an XML DTD. One of the biggest XML-based languages right now is the Simple Object Application Protocol (SOAP).

SOAP is being defined by a number of major industry leaders and is being designed as the way different programs share raw data and interoperate . It is also the cornerstone of Microsoft's .NET initiative.

So, to get back to the point, any programming language that supports XML can easily exchange data with other languages. Both languages simply have to know which DTD or XML schema to use to parse the information. This is where you introduce Flash into the equation. Flash 5 introduced simple XML capabilities into ActionScript. This means that Flash can now be integrated into Web applications in a variety of new exciting ways. Lots of Web application languages, such as ASP, ColdFusion, and PHP, already support XML. Integrating with these languages is simply a matter of making your Flash movies understand the XML that your server is spitting out.

Flash and XML

Both the good news and the bad news is that you don't have to pay a lot of attention to DTDs and schemas. Flash's XML parser is known as nonvalidating , which means that Flash doesn't intrinsically work with actual DTD or XML schema documents. Instead, when Flash receives some XML, you must have code in place that will check the XML and use it appropriately. Flash's XML object also doesn't support many of the newest features recently added to XML, such as namespaces (a way for defining a tag that can live at multiple "levels" of an XML document). Unfortunately, this precludes Flash from using certain new DTDs, such as SOAP. Before you attempt to start using Flash with a pre-existing XML system, it is important to make sure that Flash can fully understand that particular variety of XML.

There is one more very important point to cover about XML with Flash: It's slow. Flash was never meant to handle huge XML documents. It can parse only small (less than 25K or so, to be safe) documents. The actual size of document that will make Flash choke varies based on a number of factors, from platform (PC/Mac) to CPU speed, and even how many actual tags are in the document and how deeply those tags are nested ("deep" documents that have many levels of tags inside each other are much slower to parse than "flat" documents that have few nested levels).

Now you know what XML is, and you've learned some of the strengths and weaknesses of using it with Flash. It's time to get into actually using XML with Flash!



Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net