|
|
||
|
|
||
|
|
||
The XML class provides a flexible way to work with XML content
in Flash. It allows you to load external XML documents into Flash
and parse them into a document tree. Providing you know how to
traverse this tree, its easy to extract the
data and add it to the interface of your movie. You can use the XML
class to create XML content within Flash. You can either create an
XML string or use
Flash also provides you with a number of methods for
manipulating the structure of the XML tree. You can update the
content of text nodes and attributes, add and remove nodes, and
even change the
Flash is an
In the
|
|
||
|
|
||
|
|
||
In the previous chapter, you saw how to use the XML class in Flash. You can use this class to load external XML documents into Flash, to modify or generate new XML content, and to send XML from Flash to another application. If you want to include an external XML document in Flash, youll need to generate the content somehow.
Earlier in the book, I showed you how to generate XML documents
from XML editors, from server-side files, and even from Microsoft
Office 2003 on a PC. In this chapter, Ill look
more closely at how you can work with XML documents in Word 2003.
By the end of this chapter, youll have created
a Latest News XML-driven
application that you can update using Word 2003.
Ill cover Excel and Access 2003 in the
Youll need a PC with a copy of Microsoft
Office 2003 Professional or Enterprise edition before you can work
through the examples. You wont be able to use a
trial copy of the software, and
The Microsoft website offers comprehensive support for Office 2003 and XML in the XML in Office Development section. You can visit http://msdn.microsoft.com/office/understanding/xmloffice/default.aspx to learn more.
|
|
||
|
|
||
|
|
||
Before we get started, you need to understand why you might want to use Office 2003 to generate XML content. Microsoft Office is one of the most popular software packages used by organizations. Most people have skills in working with at least Word and Excel, and many companies store a large portion of their information within Office documents.
XML makes it possible for Office 2003 to share information with other applications, including Flash. You can use Office to generate and update XML documents. You can use XML schemas and Extensible Stylesheet Language Transformations (XSLT) style sheets to change the way Office creates these documents. You can also use XML in external software packages to create and modify Word and Excel documents.
Documents serve two purposes within Office. First, they provide storage for data. This is particularly relevant for applications like Excel and Access. They also provide formatting information about the data they store. This is particularly important in packages like Word and Excel.
When you work with XML content, youre usually more interested in the data rather than its presentation. Youll normally add style and formatting to an XML document by transforming the content with an XSLT style sheet or by using Cascading Style Sheets (CSS). Flash can also provide a presentation layer for the data.
As developers, we often populate our dynamic Flash applications from XML documents. The actual content isnt importantwe are more
One option is to provide clients with an XML editor and teach them the tag structure of their XML documents. However, for many clients, the prospect of working with raw XML may be quite daunting. Its also very easy for them to make mistakes and generate documents that arent well
Another approach is to create web forms that allow clients to update XML content using server-side files. Most clients are quite comfortable filling in web forms in a web browser. Its a good solution, but someone has to build the web forms, which means the client ends up paying extra. The forms also have to run through a web server, so this approach wont work as easily in stand-alone applications, for example, those running from CD-ROMs.
You can use Office 2003 to provide another solution to this problem by
Ive used this approach successfully with a number of clients. Because theyre comfortable with Office 2003, its not too much of a stretch for them to work with data and generate XML content. You can find out more about one of my clients who uses this approach in Chapter 1.
If XML functionality is available in Word, Excel, and Access 2003, how do you decide which application you should use? In part, that depends on your clients skill levels, but its also important to understand the data structures supported by each package.
Within Microsoft Office 2003, both Word and Excel come with their own built-in XML vocabularies. Both packages can describe document structures and content using a set of predefined XML elements. Word 2003 uses WordprocessingML while Excel uses SpreadsheetML. Word and Excel can
You can find out more about these languages at www.microsoft.com/office/xml/default.mspx. You can also download the documentation for the XML schemas for Microsoft products from www.microsoft.com/downloads/details.aspx?FamilyId=FE118952-3547-420A-A412-00A2662442D9&displaylang=en. The schemas come with reference documentation in the form of a help file.
Access 2003 allows you to export existing data in XML format. Unlike the other Office applications, it doesnt have its own XML vocabulary. Other Microsoft applications have varying levels of XML support. PowerPoint 2003 and Outlook 2003 dont include XML features. Visio has had XML support since the release of the XP version. Visio 2003 uses the
DataDiagramingML
language and supports Scalable Vector Graphics (SVG), an XML-based standard for describing graphical elements. The Enterprise edition of Office 2003 includes an additional product, InfoPath, that works
You can also use InfoPath, Word, Excel, and Access 2003 to
You dont have to use the built-in languages within Word and Excel 2003 in the XML documents that you generate. Instead, you can transform Office documents using XSLT style sheets and XML schemas. This allows you to extract the data from the document and ignore formatting information. In other words, you can create your own data structures for the XML documents. If you want to find out more about style sheets and schemas, refer back to Chapter 3.
You can structure data in many different ways. Some of it is
Word documents serve two purposesthey manage both style and content. We dont use Word to manage complicated tables of datathats often best left to Excel. Instead, were usually interested in template-style information, for example, a form letter or report. This gives you a clue about how best to use Word for generating XML documents.
Word 2003 doesnt generate repeating XML information particularly well, although there are some exceptions to this rule. Instead, you should treat Word as a template or form for generating XML content. You fill in the information and Word creates the XML document. This means that you should use Word for text-based Flash applications. An example of this is a latest news item display or a content management system, where the content is restricted to a fixed set of categories. Well work through an example application later in this chapter.
Excel, on the other hand, is most concerned with data and data analysis. We often use Excel to manage flat-file or list databases. Although formatting the data is important, it is a secondary consideration. The grid structure within Excel makes it easy for us to format and manipulate list-based data.
The Excel interface gives you a good idea about the type of XML structures that it will support. Excel works best with grid-based content, particularly data that you can describe in terms of rows and
Access 2003 is a relational database so it works best with groups of data that are
In the rest of this chapter, Ill focus on Word 2003. Youll learn how to set up a Word document that generates XML content for use in Flash. Well work through several examples to