1 / 31

Integrating Databases with XML

Integrating Databases with XML. Ellen Pearlman Eileen Mullin Programming the Web Using XML. Learning Objectives. Understanding the differences between focusing on data versus documents when working with databases and XML Discovering how to use XML with relational databases

jacoba
Télécharger la présentation

Integrating Databases with XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Integrating Databases with XML Ellen Pearlman Eileen Mullin Programming the Web Using XML

  2. Learning Objectives • Understanding the differences between focusing on data versus documents when working with databases and XML • Discovering how to use XML with relational databases • Learning what a native XML database is • Knowing when to use a native XML database • Gaining familiarity with how databases vendors utilize XML

  3. An Introduction to Using Databases With XML • The tasks that your data is used for should influence what kind of database you need. • You can use document-centric XML when searching for and displaying full documents is an important business requirement. • The type of database best suited for this task would likely be a native XML database or a content management system.

  4. An Introduction to Using Databases With XML (2) • E-commerce applications for taking orders and completing online credit card transactions can use XML as a data transport. • Here, XML is only used only for messaging, to transfer the data back and forth from the database to any documents (for example, to an order receipt). This is an example of data-centric XML. • In this case, you could use a traditional database and software that would enable the transfer of information between XML documents and the database.

  5. XML-Enabled Database • Traditional databases that can work with XML are also known as XML-enabled databases, because they have been developed to transfer data seamlessly between their data stores and XML documents. • Major commercial vendors of database software and servers have all developed extensive sets of components or solutions to work with XML-related information in their databases.

  6. Data-Centric XML • In data-centric XML, data is pulled from a database to be used in an XML document. Flight schedules, sales receipts, or stock quotes are all examples of data-centric documents. • The actual information retrieval with XML is usually done by computers with little or no human intervention. • Data-centric documents usually have consistently structured data.

  7. Example of Data-Centric XML <Facility> <ID>3</ID> <AgencyName>Bureau of Reclamation</AgencyName> <RecGovURL>http://www.recreation.gov/detail.cfm?ID=(3)</RecGovURL> <JurisdictionType>Federal</JurisdictionType> <FacilityName>Canyon Lake</FacilityName> <FacilityURL>http://www.fs.fed.us/r3/tonto</FacilityURL> <Latitude>-1.05878e+006</Latitude> <Longititude>-1.20003e+006</Longititude> <StreetAddress1>Tonto National Forest</StreetAddress1> <StreetAddress2>2324 E. McDowall Road</StreetAddress2> <StreetAddress3>P.O. Box 5348</StreetAddress3> <City>Phoenix</City> <State_Territory_Provence>AZ</State_Territory_Provence> <PostalCode>85010</PostalCode> <Country>USA</Country> <Phone>602-225-5200</Phone> <States>AZ</States> </Facility>

  8. Document-Centric XML • As the name implies, document-centric XML describes documents that are meant for humans to browse and read through. • Document-centric XML documents are less structured than data-centric XML documents. • Document-centric documents frequently hold elements that in turn contain both free-form text and other elements, which is known as mixed content.

  9. Example of Document-Centric XML <Class> <Introduction> <ClassName>Choosing and Using Consumer Electronics</ClassName> is taught by <Instructor>Ross Rubin</Instructor>. When school is in session, this class is held every <Weekday>Monday</Weekday> from <StartTime>6:00 p.m.</StartTime> until <EndTime>8:30 p.m.</EndTime>. </Introduction> <Description> <Para>Digital cameras, color printers and scanners, and a bevy of personal computers are now widely available to consumers. But how can you be confident you're getting what you paid for and making the most of it? In this class you'll gain an overview of the latest in video cameras, color scanners, color printers, and other consumer technology products. </Para> <Para>You'll also learn:</Para> <List> <LineItem>How to brainstorm ways to put your new equipment to use</LineItem> <LineItem>When to upgrade and when to invest in a new model</LineItem> <LineItem>What sales channels offer the best deals, and which to avoid</LineItem> </List> </Description> </Class>

  10. Database Storage for Data-Centric Documents • Data-centric documents lend themselves well to storage in traditional kinds of databases. • These include relational databases, object-oriented databases, and hierarchical databases. • Transferring data to and from a traditional database with XML may be accomplished with middleware. • You can also directly transfer data to and from a traditional database with XML, without middleware, if the database has its own built-in capabilities for doing so. If a database has such capabilities, it is said to be XML-enabled.

  11. Database Storage for Document-Centric Documents • Document-centric documents are best stored in either: • a native XML database, which is a database specifically designed for holding XML content, or • a content management system, which is an application that’s built on a native XML database that's intended solely for managing documents.

  12. Transferring Information Between Traditional Databases and XML • A database is essentially a computerized system for record-keeping. • A database is typically associated with the software that’s used to update and query the database. • Traditional databases come in a variety of flavors, from relational databases and object-oriented databases to hierarchical databases and information network databases.

  13. Relational Databases • A relational database is a database in which related information is stored in tables, and data is linked between tables. • Each individual item and the information collected about it is known as a record. • Each record should be assigned a unique number. • Relational databases contain more than one table.

  14. Example: Relational Database

  15. Structured Query Language (SQL) • A relational database implements a standardized set of operations on its stored data using a programming language called Structured Query Language (SQL). • SQL provides an interface that’s intended to be much easier to learn than most programming languages. • You can use SQL to manipulate data in database systems like Microsoft Access, Oracle, DB2, Sybase, Informix, Microsoft SQL Server, among others.

  16. A Brief Introduction to SQL • SQL lets you explicitly select data from the tables located in a database. • The keywords used in the most basic SQL statement reflect that you want to SELECT information FROM a table: SELECT "column_name" FROM "table_name"

  17. What’s Next: Mapping and Querying • To transfer data smoothly between XML documents and a database, you'll need to ensure that each element in your XML documents has an equivalent in the database's own schema. • This requires a mapping of the XML document schema to the database schema. • The database software then references this mapping as it transfers data.

  18. What’s Next: Mapping and Querying (2) • The software that’s used to transfer data may utilize querying – with an XML query language, such as XPath or XQuery – in order to transfer data this way. • Alternatively, the software that’s used may directly transfer data. • To directly map the data on a one-to-one basis, data transfer software usually uses XSLT to transform the document to a structure that the database expects and vice versa.

  19. Mapping Document Schemas to Database Schemas • What gets mapped between XML documents and database schemas usually includes elements, attributes, and text. • Although the omitted information is important to XML documents, only the data is really of any relevance to a database. • There are two kinds of mappings most frequently used to connect an XML document schema to traditional kinds of databases: • table-based mapping • object-relational mapping

  20. Table-Based Mapping • Table-based mapping represents XML documents as a series of tables. • Many middleware vendors utilize table-based mapping in their software for transferring data back-and-forth between XML documents and a relational database.

  21. A Series of Tables in a Relational Database

  22. Object-Relational Mapping • The object-relational mapping method represents your data as a branching tree of objects. Each real-world item is represented by a corresponding item in the database. • Object-relational mapping distinguishes between elements that XML Schemas defines as complex types and simple types. • Object-relational mapping correlates complex-type elements to tables and simple-type elements to columns.

  23. Example: Object-Relational Mapping

  24. Querying XML Documents to Transfer Data to Databases • Using a query language to retrieve data in XML from a database is a developing approach that is gaining in popularity among database vendors. • Similarly, there are SQL-based query languages that use standardized SQL statements in querying the database; the results returned from the database are then transformed to XML. • A group of companies is working to develop standardized XML extensions to SQL in an undertaking called SQL/XML.

  25. Example: Querying XML Documents SELECT XMLElement("Invoice", XMLAttributes(IDNumber), XMLElement("Date", Date), XMLElement("Client", Client), XMLElement("ScopeOfWork", ScopeOfWork)) AS xmlresults FROM Invoices WHERE IDNumber ="ZDM018“ This query would produce the XML document below in a column labeled xmlresults: <Invoice IDNumber="ZDM018"> <Date>08/31/2003</Date> <Client>Ziff Davis Media</Client> <ScopeOfWork>Provided computer instruction to writers at Baseline magazine.</ScopeOfWork > </Invoice>

  26. Directly Transferring Data to Databases • XML has the potential to be a far more sophisticated language for data modeling language data model underlying many relational databases. • As a result, storing your XML data in a SQL database can be more complicated than retrieving XML results back from a database. • The most difficult part can be identifying a workable mapping from the nested data structures in XML documents to flat relational tables with rows and columns.

  27. Wrapper Elements • Wrapper elements provide two functions. • First, they add a naming structure that simplifies understanding the other elements in the document. • Next, wrapper elements are frequently used as a means of data typing, which means identifying the business purpose of the elements contained therein. • Although wrapper elements can be most helpful for classifying your XML data, they impose an extra layer of structure when the elements in your XML documents get mapped to the database.

  28. Using XML with Oracle • Oracle has XML-enabled database technology built into its Oracle9i database server. • Oracle processes XML documents in one of two ways: • composed XML documents, which are stored as a Large Object (LOB) • decomposed XML documents, which are stored in relational tables. The XML tags are mapped to corresponding tables in the database's tables.

  29. Using XML with Microsoft’s SQL Server 2000 • Microsoft has added XML functionality to its SQL Server 2000 database server that lets you view your whole relational database as XML. • These capabilities are intended to let you work with your SQL Server 2000 data as a series of XML documents, although the underlying data is untouched. • With SQL Server 2000, you can develop XPath queries that would be much shorter than the equivalent SQL statements, which should simplify development.

  30. Using XML with IBM’s DB2 • IBM has developed an XML Registry/Repository (XRR) package for storing and managing XML data. • XRR includes five separate services. • A registry for groups to submit DTDs, schemas, or stylesheets • A separate registration service for organizations • A search service • An administration service that manages the status of users and overall registry content. • Finally, an access service lets users download registered objects from the registry.

  31. The End

More Related