25
XML For Dummies Book Author : Lucinda Dykes & Ed Tittle Slides Prepared By: Son TN Chapter 17 : Serving Up the Data: XML and Databases

Xml For Dummies Chapter 17 Serving Up The Data Xml And Databases

Embed Size (px)

Citation preview

Page 1: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

XML For DummiesBook Author : Lucinda Dykes & Ed Tittle

Slides Prepared By: Son TNChapter 17 : Serving Up the Data: XML and

Databases

Page 2: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

Contents1.Using Databases with XML

2.Creating XML from Database Files

3.Using XML with Access 2003

Page 3: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases
Page 4: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.1 Using Databases with XMLThe connection between databases and XML is a logical one.

All the major database systems — from Oracle to Microsoft SQL Server and beyond — have XML utilities that help you work with XML in the context of the database.

Another common use of databases with XML is to let the database serve as an index to the content described with XML.

If your solution includes a database, you need to think about how, if at all, your XML documents will interface with the database.

Page 5: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.1 Using Databases with XML (Cont)For example, an online article archive uses XML as the

format for describing articles.

An online article archive, takes advantage of the individual strengths of both XML and databases

XML provides detailed structural information about the articles, which a database can’t handle very well.

The data about the articles (the article metadata) stored in the database can be searched and filtered according to all manner of criteria — something XML isn’t particularly suited for.

Page 6: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.1.1 Text-intensive XMLText-intensive XML documents can also be configured to

work with a database.

For example :

A database can store paragraphs of text.

An XML document can then connect with the database to import a particular block of text information to add to the content of the XML document.

When the information in the database changes, the content of the XML document changes, too.

Page 7: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.1.2 Data-intensive XML Interacting with a database is “natural” for XML

documents with data intensive content.

Businesses commonly use databases to store data intensive content.

This content can be imported from a database to populate XML documents with the most current version of the data.

The XML document can then be displayed in print, on a Web page, in an online form, or on a mobile device.

Page 8: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2 Creating XML from Database Files In the following section , We focus on using an Access

database with XML documents in :

Microsoft Word 2003.

Microsoft InfoPath.

Altova XMLSpy.

Page 9: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.1 Using Word 2003All versions of Word 2003 can save documents in XML format.To import database information into a Word 2003 XML

document, follow these steps:1. Open Word 2003, choose File New from the main menu, and then ➪

choose XML Document from the New Document task pane on the left.

2. Select View Toolbars Database.➪ ➪3. Click the Insert Database icon on the Database toolbar.4. Click the Get Data button, browse to the bookstore.mdb file, and

then click Open.5. If you want to use Word’s default table formatting options, move

on to Step 6.6. Click the Insert Data button in the Database dialog box.7. From the Insert Data dialog box, choose All or a range of values

for the Insert records option and then click OK.

Page 10: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.1 Using Word 2003 (Cont)

Your XML file now displays the database information in a table, asshown in Figure 17-1.

Page 11: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.2 Using InfoPath InfoPath allows you to import database information into a blank

InfoPath form. To import database information and create a new InfoPath form, follow

these steps:1. Open InfoPath, and choose File Design a Form to open the Design a Form ➪

task pane.

2. From the Design a Form task pane, choose New from Data Connection.

3. Choose Database from the Data Connection Wizard and then click Next.

4. Click the Select Database button in the next screen in the wizard, browse to the location of bookstore.mdb, and then click Open.

5. Click Next in the wizard screen and then enter a name for the data connection in the text field labeled “Enter a name for this data connection.”

Page 12: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.2 Using InfoPath (Cont)6. Click Finish.

7. Insert the cursor in the Drag Data Fields Here box on the form template.

8. Select the dataFields folder from the task pane and then right-click the folder.

9. Choose Section with Controls from the contextual menu.

10. To format the display, right-click the Repeating Section label; choose Borders and Shading; use the main tab of the Borders and Shading dialog box to make your selections for border width, color, and size; and then click the Shading tab to choose a background color.

11. With your data fields out of the way, insert the cursor into the Drag Query Fields Here box on the form template.

12. Select the queryFields folder from the task pane, and right-click the folder.

Page 13: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.2 Using InfoPath (Cont)13. Choose Section with Controls from the contextual menu.

14. Put the cursor in the Query box, and add a title for this box. Do the same in the Data box (we used Book Query and Book Data for our titles).

15. In the area that says Click to Add a Title, enter a title for your form.

16. In the area that says Click to Add Form Content, add some instructions for form users.

17. Choose File Save and then click Save in the Microsoft Office InfoPath ➪window to save the form design changes.

18. Enter a name for your form (we used Book.xsn) and then click Save.

19. Choose File Preview Form Default to create a functional Preview file, and ➪ ➪test out the form!

Page 14: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.2 Using InfoPath (Cont)

Figure 17-2 shows the Preview version of the Book form.

Page 15: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.3 Using XMLSpy XMLSpy is a multifaceted XML tool. Follow these steps to import information from a database and

create a new XML file:

1. Open XMLSpy, and choose Convert Import Database Data from the ➪main menu.

2. In the Import Database data dialog box, choose Convert Database Data into XML, and click OK.

3. Select Microsoft Access (ADO) from the Select a Source Database window and then click Next.

4. In the Select a MS Access Database window, click the Browse button and navigate to bookstore.mdb; then click Next.

Page 16: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.3 Using XMLSpy (Cont)5. In the Import Database Data window, click the Choose Database

Table button.

6. In the Choose a Database Table window, select Book and then click OK.

7. In the Import Database Data window, go to the Import Settings section and choose the Compatible with Schema Data Types option, check the boxes for the Exclude Primary/Foreign Keys and the Create Empty Elements from Empty Fields options, and then click the Import button.

8. Click the Text tab at the bottom of the file to see the underlying markup.

Page 17: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.3 Using XMLSpy (Cont)

Page 18: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.3 Using XMLSpy (Cont) Here’s how to export data from an XML file to a database:

1. Choose File Open from the main menu in XMLSpy. Navigate to your ➪XML file in the Open dialog box and then click Open.

2. Choose Convert Export to Text Files/Database.➪

3. From the Export to Text Files/Databases dialog box, select Convert XML into Text Files or Database Data and then click OK.

4. In the Automatic Fields section of the Export to Text Files/Database window, uncheck the Independent Primary Key Counter for Every Element box and then click the Export to Database button.

5. Click OK in the next window (Export to Database) to create the database file.

Page 19: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.2.3 Using XMLSpy (Cont)6. Open the database file in Access and then click the Row table to view

the table contents, as shown in Figure 17-4.

Page 20: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.3 Using XML with Access 2003 Using Access 2003, you can import data from an XML file as well

as export data as XML files.

The import and export methods in Access 2003 also allow you to import and export XML data, schema information, and/or presentation information to and from :

Microsoft SQL Server 2000 Desktop Engine,

Microsoft SQL Server 7.0 or later.

The Microsoft Jet Database Engine.

Access 2003 also supports the use of XSLT files when importing or exporting XML data.

Page 21: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.3 Using XML with Access 2003 (Cont) Follow these instructions to import data from an XML file into

Access 2003:

1. Select File New to create a new database file.➪

2. Select Blank Database from the New list in the New File task pane.

3. Enter a name for the database in the File New Database window and then click Create.

4. To get the import ball rolling, choose File Get External ➪Data Import.➪

5. In the Import dialog box, choose XML from the Files of Type dropdown menu and then browse to the location of your XML file. Select your XML file and then click Import.

Page 22: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.3 Using XML with Access 2003 (Cont)6. Click the Options button to show all the import options, as shown in

Figure 17-5.

Page 23: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.3 Using XML with Access 2003 (Cont)Follow these instructions to export data from an Access 2003

table to an XML file:1. Open the database table in Access and then select

File Export.➪2. In the Export dialog box, choose XML in the Save as Type drop-

down menu and then click the Export button. (As Figure 17.6 )

3. Depending on your choices in the Export XML dialog box, Access 2003 will create the following files:

An XML file An XML Schema file An XSLT file

Page 24: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.3 Using XML with Access 2003 (Cont) In addition to exporting XML files from Access 2003

database tables, you can export Access 2003 database tables as RTF (Rich Text Format) files.

Page 25: Xml For Dummies   Chapter 17 Serving Up The Data Xml And Databases

17.4 Summary In this chapter, you have the opportunity to get some

hands-on practice with XML and databases.

Using three different software applications (Word, InfoPath, and XMLSpy), you find out how to import data from a database to an XML document and how to export data from an XML document to a database.

You also discover how to export data directly from Access 2003 in several different file formats.