Comparison with Relational Data Inefficient:tags,which in effect represent schema information,are repeated Better than relational tuples as a data-exchange format Unlike relational tuples,XML data is self-documenting due to presence of tags Non-rigid format:tags can be added Allows nested structures Wide acceptance,not only in database systems,but also in browsers, tools,and applications Database System Concepts-7th Edition 30.7 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 30.7 ©Silberschatz, Korth and Sudarshan th Edition Comparison with Relational Data ▪ Inefficient: tags, which in effect represent schema information, are repeated ▪ Better than relational tuples as a data-exchange format • Unlike relational tuples, XML data is self-documenting due to presence of tags • Non-rigid format: tags can be added • Allows nested structures • Wide acceptance, not only in database systems, but also in browsers, tools, and applications
Structure of XML Data Tag:label for a section of data Element:section of data beginning with <tagname>and ending with matching </tagname> Elements must be properly nested ·Proper nesting .<course>...<title>....</title></course> ·Improper nesting <course>...<title>....</course></title> 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 element Database System Concepts-7th Edition 30.8 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 30.8 ©Silberschatz, Korth and Sudarshan th Edition Structure of XML Data ▪ Tag: label for a section of data ▪ Element: section of data beginning with <tagname> and ending with matching </tagname> ▪ Elements must be properly nested • Proper nesting ▪ <course> … <title> …. </title> </course> • Improper nesting ▪ <course> … <title> …. </course> </title> • 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 element
Example of Nested Elements <purchase order> <identifier>P-101 </identifier> <purchaser>....</purchaser> <itemlist> <item> <identifier>RS1 </identifier> <description>Atom powered rocket sled </description> <quantity>2 </quantity> <price>199.95 </price> </item> <item> <identifier>SG2 </identifier> <description>Superb glue </description> <quantity>1 </quantity> <unit-of-measure>liter </unit-of-measure> <price>29.95 </price> </item> </itemlist> </purchase order> Database System Concepts-7th Edition 30.9 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 30.9 ©Silberschatz, Korth and Sudarshan th Edition Example of Nested Elements <purchase_order> <identifier> P-101 </identifier> <purchaser> …. </purchaser> <itemlist> <item> <identifier> RS1 </identifier> <description> Atom powered rocket sled </description> <quantity> 2 </quantity> <price> 199.95 </price> </item> <item> <identifier> SG2 </identifier> <description> Superb glue </description> <quantity> 1 </quantity> <unit-of-measure> liter </unit-of-measure> <price> 29.95 </price> </item> </itemlist> </purchase_order>
Motivation for Nesting Nesting of data is useful in data transfer Example:elements representing item nested within an itemlist element Nesting 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 databases But nesting is appropriate when transferring data External application does not have direct access to data referenced by a foreign key Database System Concepts-7th Edition 30.10 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 30.10 ©Silberschatz, Korth and Sudarshan th Edition Motivation for Nesting ▪ Nesting of data is useful in data transfer • Example: elements representing item nested within an itemlist element ▪ Nesting 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 databases ▪ But nesting is appropriate when transferring data • External application does not have direct access to data referenced by a foreign key
Structure of XML Data (Cont.) Mixture of text with sub-elements is legal in XML. 。 Example: <course> This course is being offered for the first time in 2009 <course id>BIO-399 </course id> <title>Computational Biology </title> <dept name>Biology </dept name> <credits>3 </credits> </course> Useful for document markup,but discouraged for data representation Database System Concepts-7th Edition 30.11 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 30.11 ©Silberschatz, Korth and Sudarshan th Edition Structure of XML Data (Cont.) ▪ Mixture of text with sub-elements is legal in XML. • Example: <course> This course is being offered for the first time in 2009. <course id> BIO-399 </course id> <title> Computational Biology </title> <dept name> Biology </dept name> <credits> 3 </credits> </course> • Useful for document markup, but discouraged for data representation