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


Published on

Published in: Technology, News & Politics
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

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

  1. 1. XML For Dummies<br />Book Author : Lucinda Dykes & Ed Tittle<br />Slides Prepared By: Son TN<br />Chapter 17 : Serving Up the Data: XML and Databases<br />
  2. 2. Contents<br />Using Databases with XML<br />Creating XML from Database Files<br />Using XML with Access 2003<br />
  3. 3.
  4. 4. 17.1 Using Databases with XML<br />The connection between databases and XML is a logical one.<br />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.<br />Another common use of databases with XML is to let the database serve as an index to the content described with XML.<br />If your solution includes a database, you need to think about how, if at all, your XML documents will interface with the database.<br />
  5. 5. 17.1 Using Databases with XML (Cont)<br />For example, an online article archive uses XML as the format for describing articles.<br />An online article archive, takes advantage of the individual strengths of both XML and databases<br />XML provides detailed structural information about the articles, which a database can’t handle very well.<br />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.<br />
  6. 6. 17.1.1 Text-intensive XML<br />Text-intensive XML documents can also be configuredto work with a database.<br />For example :<br />A database can store paragraphs of text.<br />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. <br />When the information in the database changes, the content of the XML document changes, too.<br />
  7. 7. 17.1.2 Data-intensive XML<br />Interacting with a database is “natural” for XML documents with data intensive content.<br />Businesses commonly use databases to store data intensive content.<br />This content can be imported from a database to populate XML documents with the most current version of the data. <br />The XML document can then be displayed in print, on a Web page, in an online form, or on a mobile device.<br />
  8. 8. 17.2 Creating XML from Database Files<br />In the following section , We focus on using an Access database with XML documents in : <br />Microsoft Word 2003.<br />Microsoft InfoPath.<br />AltovaXMLSpy.<br />
  9. 9. 17.2.1 Using Word 2003<br />All versions of Word 2003 can save documents in XML format.<br />To import database information into a Word 2003 XML document, follow these steps:<br />Open Word 2003, choose File➪New from the main menu, and then choose XML Document from the New Document task pane on the left.<br />Select View➪Toolbars➪Database.<br />Click the Insert Database icon on the Database toolbar.<br />Click the Get Data button, browse to the bookstore.mdb file, and then click Open.<br />If you want to use Word’s default table formatting options, move on to Step 6.<br />Click the Insert Data button in the Database dialog box.<br />From the Insert Data dialog box, choose All or a range of values for the Insert records option and then click OK.<br />
  10. 10. 17.2.1 Using Word 2003 (Cont)<br />Your XML file now displays the database information in a table, as<br />shown in Figure 17-1.<br />
  11. 11. 17.2.2 Using InfoPath<br />InfoPath allows you to import database information into a blank InfoPath form.<br />To import database information and create a new InfoPath form, follow these steps:<br />Open InfoPath, and choose File➪Design a Form to open the Design a Form task pane.<br />From the Design a Form task pane, choose New from Data Connection.<br />Choose Database from the Data Connection Wizard and then click Next.<br />Click the Select Database button in the next screen in the wizard, browse to the location of bookstore.mdb, and then click Open.<br />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.”<br />
  12. 12. 17.2.2 Using InfoPath (Cont)<br />Click Finish.<br />Insert the cursor in the Drag Data Fields Here box on the form template.<br />Select the dataFields folder from the task pane and then right-click the folder.<br />Choose Section with Controls from the contextual menu.<br />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.<br />With your data fields out of the way, insert the cursor into the Drag Query Fields Here box on the form template.<br />Select the queryFields folder from the task pane, and right-click the folder.<br />
  13. 13. 17.2.2 Using InfoPath (Cont)<br />Choose Section with Controls from the contextual menu.<br />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).<br />In the area that says Click to Add a Title, enter a title for your form.<br />In the area that says Click to Add Form Content, add some instructions for form users.<br />Choose File➪Save and then click Save in the Microsoft Office InfoPath window to save the form design changes.<br />Enter a name for your form (we used Book.xsn) and then click Save.<br />Choose File➪PreviewForm➪Default to create a functional Preview file, and test out the form!<br />
  14. 14. 17.2.2 Using InfoPath (Cont)<br />Figure 17-2 shows the Preview version of the Book form.<br />
  15. 15. 17.2.3 Using XMLSpy<br />XMLSpy is a multifaceted XML tool.<br />Follow these steps to import information from a database and create a new XML file:<br />Open XMLSpy, and choose Convert➪Import Database Data from the main menu.<br />In the Import Database data dialog box, choose Convert Database Data into XML, and click OK.<br />Select Microsoft Access (ADO) from the Select a Source Database window and then click Next.<br />In the Select a MS Access Database window, click the Browse button and navigate to bookstore.mdb; then click Next.<br />
  16. 16. 17.2.3 Using XMLSpy (Cont)<br />In the Import Database Data window, click the Choose Database Table button.<br />In the Choose a Database Table window, select Book and then click OK.<br />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.<br />Click the Text tab at the bottom of the file to see the underlying markup.<br />
  17. 17. 17.2.3 Using XMLSpy (Cont)<br />
  18. 18. 17.2.3 Using XMLSpy (Cont)<br />Here’s how to export data from an XML file to a database:<br />Choose File➪Open from the main menu in XMLSpy. Navigate to your XML file in the Open dialog box and then click Open.<br />Choose Convert➪Export to Text Files/Database.<br />From the Export to Text Files/Databases dialog box, select Convert XML into Text Files or Database Data and then click OK.<br />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.<br />Click OK in the next window (Export to Database) to create the database file.<br />
  19. 19. 17.2.3 Using XMLSpy (Cont)<br />Open the database file in Access and then click the Row table to view the table contents, as shown in Figure 17-4.<br />
  20. 20. 17.3 Using XML with Access 2003<br />Using Access 2003, you can import data from an XML file as well as export data as XML files.<br />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 :<br />Microsoft SQL Server 2000 Desktop Engine, <br />Microsoft SQL Server 7.0 or later.<br />The Microsoft Jet Database Engine.<br />Access 2003 also supports the use of XSLT files when importing or exporting XML data.<br />
  21. 21. 17.3 Using XML with Access 2003 (Cont)<br />Follow these instructions to import data from an XML file into Access 2003:<br />Select File➪New to create a new database file.<br />Select Blank Database from the New list in the New File task pane.<br />Enter a name for the database in the File New Database window and then click Create.<br />To get the import ball rolling, choose File➪Get External Data➪Import.<br />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.<br />
  22. 22. 17.3 Using XML with Access 2003 (Cont)<br />Click the Options button to show all the import options, as shown in Figure 17-5.<br />
  23. 23. 17.3 Using XML with Access 2003 (Cont)<br />Follow these instructions to export data from an Access 2003 table to an XML file:<br />Open the database table in Access and then select File➪Export.<br />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 )<br />Depending on your choices in the Export XML dialog box, Access 2003 will create the following files:<br /><ul><li>An XML file
  24. 24. An XML Schema file
  25. 25. An XSLT file</li></li></ul><li>17.3 Using XML with Access 2003 (Cont)<br />In addition to exporting XML files from Access 2003 database tables, you can export Access 2003 database tables as RTF (Rich Text Format) files.<br />
  26. 26. 17.4 Summary<br />In this chapter, you have the opportunity to get some hands-on practice with XML and databases.<br />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.<br />You also discover how to export data directly from Access 2003 in several different file formats.<br />