Database DesignPowerPoint PresentationSlide 3XML Introduction (1)XML Introduction (2)XML Motivations (1)XML Motivations (2)Structure of XML DataEx: of Nested ElementsMotivation for NestingStructure of XML (2)AttributesAttributes vs. SubelementsMore on XML SyntaxNamespacesXML Document SchemaDocument Type Definition (DTD)Element Specification in DTDBank DTDAttributes Spec in DTDIDs and IDREFsBank DTD with AttributesXML data with ID and IDREF attributesLimitations of DTDsXML SchemaXML Schema Version of Bank DTDQuerying and Transforming XML DataTree Model of XML DataXpath (1)XPath (2)Functions in XPathMore XPath FeaturesXSLTXSLT Templates (1)XSLT Templates (2)Creating XML Output (1)Creating XML Output (2)Structural RecursionSorting in XSLTXQueryFLWR Syntax in XQueryJoinsChanging Nesting StructureXQuery Path ExpressionsSorting in XQueryFunctions and Other XQuery FeaturesApplication Program InterfaceStorage of XML DataStoring XML in Relational DatabasesStoring XML as RelationsStoring XML in RelationsDiscussion Questions2003SJSU -- CmpE L13-S1 XMLDatabase Design Dr. M.E. Fayad, ProfessorComputer Engineering Department, Room #283I College of EngineeringSan José State UniversityOne Washington SquareSan José, CA 95192-0180 http://www.engr.sjsu.edu/~fayad2003SJSU – CmpE --- M.E. Fayad L13-S2 XML2Lesson 13:XML2003SJSU – CmpE --- M.E. Fayad L13-S3 XML Lesson ObjectivesObjectives3 Introduce XML Understand The motivation behind XML Explore the structure of XML: Document Type Definition XML Schema XSLT Explore querying and transforming XML data Learn about storing XML in relational databases2003SJSU – CmpE --- M.E. Fayad L13-S4 XMLXML: Extensible Markup LanguageDefined by the WWW Consortium (W3C)Originally intended as a document markup language not a database language–Documents have tags giving extra information about sections of the document•E.g. <title> XML </title> <slide> Introduction …</slide>–Derived from SGML (Standard Generalized Markup Language), but simpler to use than SGML–Extensible, unlike HTML•Users can add new tags, and separately specify how the tag should be handled for display–Goal was (is?) to replace HTML as the language for publishing documents on the Web4XML Introduction (1)2003SJSU – CmpE --- M.E. Fayad L13-S5 XMLThe ability to specify new tags, and to create nested tag structures made XML a great way to exchange data, not just documents.–Much of the use of XML has been in data exchange applications, not as a replacement for HTMLTags make data (relatively) self-documenting –E.g. <bank> <account> <account-number> A-101 </account-number> <branch-name> Downtown </branch-name> <balance> 500 </balance> </account> <depositor> <account-number> A-101 </account-number> <customer-name> Johnson </customer-name> </depositor> </bank>5XML Introduction (2)2003SJSU – CmpE --- M.E. Fayad L13-S6 XMLData interchange is critical in today’s networked world–Examples:•Banking: funds transfer•Order processing (especially inter-company orders)•Scientific data–Chemistry: ChemML, …–Genetics: BSML (Bio-Sequence Markup Language), …–Paper flow of information between organizations is being replaced by electronic flow of informationEach application area has its own set of standards for representing informationXML has become the basis for all new generation data interchange formats6XML Motivations (1)2003SJSU – CmpE --- M.E. Fayad L13-S7 XMLEarlier generation formats were based on plain text with line headers indicating the meaning of fields–Similar in concept to email headers–Does not allow for nested structures, no standard “type” language–Tied too closely to low level document structure (lines, spaces, etc)Each XML based standard defines what are valid elements, using– XML type specification languages to specify the syntax•DTD (Document Type Descriptors)•XML Schema–Plus textual descriptions of the semanticsXML allows new tags to be defined as required–However, this may be constrained by DTDsA wide variety of tools is available for parsing, browsing and querying XML documents/data7XML Motivations (2)2003SJSU – CmpE --- M.E. Fayad L13-S8 XMLTag: label for a section of dataElement: section of data beginning with <tagname> and ending with matching </tagname>Elements must be properly nested–Proper nesting• <account> … <balance> …. </balance> </account> –Improper nesting • <account> … <balance> …. </account> </balance> –Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element.Every document must have a single top-level element8Structure of XML Data2003SJSU – CmpE --- M.E. Fayad L13-S9 XML<bank-1> <customer> <customer-name> Hayes </customer-name> <customer-street> Main </customer-street> <customer-city> Harrison </customer-city> <account> <account-number> A-102 </account-number> <branch-name> Perryridge </branch-name> <balance> 400 </balance> </account> <account> … </account> </customer> . . </bank-1>9Ex: of Nested Elements2003SJSU – CmpE --- M.E. Fayad L13-S10 XMLNesting of data is useful in data transfer–Example: elements representing customer-id, customer name, and address nested within an order elementNesting is not supported, or discouraged, in relational databases–With multiple orders, customer name and address are stored redundantly–normalization replaces nested structures in each order by foreign key into table storing customer name and address information–Nesting is supported in object-relational databasesBut nesting is appropriate when transferring data–External application does not have direct access to data referenced by a foreign key10Motivation for Nesting2003SJSU – CmpE --- M.E. Fayad L13-S11 XMLMixture of text with sub-elements is legal in XML. –Example: <account> This account is seldom used any more. <account-number> A-102</account-number> <branch-name> Perryridge</branch-name> <balance>400 </balance></account>–Useful for document markup, but discouraged for data representation11Structure of XML (2)2003SJSU – CmpE --- M.E. Fayad L13-S12
View Full Document