Difference between revisions of "Databases"

From Suhrid.net Wiki
Jump to navigationJump to search
Line 65: Line 65:
 
* Having no DTD offers flexibility of data.
 
* Having no DTD offers flexibility of data.
 
* DTD also can specify pointer types - an element can have an ID and another element can refer to it using an IDREF.
 
* DTD also can specify pointer types - an element can have an ID and another element can refer to it using an IDREF.
 +
 +
== XSD ==
 +
 +
* Like DTD, but more comprehensive.
 +
* XSD is written in XML itself.
 +
* Everything in DTD is string, in XSD e.g., we can specify that an attribute should be of a specific type.
 +
* Pointers can be typed, so we can enforce that a reference is made to a particular type and not just global like in DTD's
 +
* Also specify min/max constraints on elements

Revision as of 05:20, 4 January 2014

Relational Databases

  • Set of named relations (tables)
  • Each relation has a set of named attributes (columns)
  • Each tuple (row) has a value for each attribute
  • Each attribute has a type (or domain)
  • All queries return relations (tables), so it can said to be compositional or closed.

XML Data

  • Alternative to relational model to store data
  • Standard for data representation and exchange
  • Document format similar to HTML, however tags represent content instead of formatting.
  • XML consists of tagged elements which can be nested, attributes of elements and the text (values/data)
  • XML document can be thought of as a tree with values/text forming the leaves.

Relational vs XML

Relational XML
Structure Tables Hierarchical/Tree
Schema Fixed in advance Flexible, self-describing. e.g. all elements need not have same attributes. (In relational, we would need to have NULL values). Inconsistencies in the structure is NOT a problem.
Queries Relatively simple Complicated compared to Relational / SQL.
Ordering Fundamentally UNORDERED. e.g. Order by clause is required in SQL in case order is desired. Ordering is implied - e.g. the way the text is laid out in the XML document or in the Stream.
Implementation Mature - native implementation Add - on. (Underlying implementation is relational)

Well formed XML

  • Single root element
  • XML parser is used to validate XML.
  • DOM parser - treats XML as a document, SAX parser - treats XML as a stream.
  • Matched tags, proper nesting
  • Unique attributes within each element

Displaying XML

  • Since XML occurs a lot on the internet, a convenient way is required to display XML.
  • Use rule based languages such as CSS, XSL to translate XML to HTML.
  • XML document is fed to a CSS/XSL interpreter alongwith rules and a HTML document is generated.

Valid XML

  • Valid XML should adhere to requirements for well formed XML
  • Also should adhere to content-specific specifications : DTD/XSD
  • DTD is a grammar-like language for specifying elements, attributes, nesting, ordering, #occurrences
  • DTD/XSD offers the benefits of "typing" - can serve as a specification. Useful for data exchange.
  • Having no DTD offers flexibility of data.
  • DTD also can specify pointer types - an element can have an ID and another element can refer to it using an IDREF.

XSD

  • Like DTD, but more comprehensive.
  • XSD is written in XML itself.
  • Everything in DTD is string, in XSD e.g., we can specify that an attribute should be of a specific type.
  • Pointers can be typed, so we can enforce that a reference is made to a particular type and not just global like in DTD's
  • Also specify min/max constraints on elements