Assignment - XML, JSON, Views, and Triggers
Both paths complete an assignment on these topics.
Extensible Markup Language (XML) is a markup language that allows for the description of data semantics. Advantages of XML include simplicity, open standard, extensibility, interoperability, and separation of data and presentation.
An XML document is a text document that contains markup in the form of tags. XML data is ordered by nature.
An XML document is well-formed if it obeys the syntax of the XML standard. This includes having a single root element, and all elements must be properly closed and nested. An XML document is valid if it is well-formed and it conforms to a Document Type Definition (DTD) or an XML Schema Definition (XSD).
XPath allows specifying path expressions to navigate the tree-structured XML document. Path descriptors are sequences of tags separated by slashes /
. The *
wild card operator can be used to denote any single tag. Attributes are referenced by putting a @
in front of their name. A predicate expression is specified inside square brackets [..]
following a tag.
Use the XML Practice Query Page to practice writing some XPath queries.
JavaScript Object Notation (JSON) is a method for serializing data objects into text form. It is human-readable, supports semi-structured data, and has supporting libraries in many programming languages. It is often used for data interchange between a client and the server.
- Values: number, strings (double quoted), true, false, null
- Objects: enclosed in { } and consist of set of key-value pairs
- Arrays: enclosed in [ ] and are lists of values
- Objects and arrays can be nested.
An online JSON validator is JSONLint.
A view is a named query. Views may be either virtual or materialized in the database. Advantages of views include data independence, easier querying, improved performance for materialized views, and the ability to enforce security constraints using GRANT/REVOKE on views instead of base tables.
Triggers are also called event-condition-action (ECA) rules. When an event occurs (such as inserting a tuple) that satisfies a given condition (any SQL boolean-valued expression) an action is performed (which is any sequence of SQL statements). Triggers provide a general way for detecting events and responding to them.
There are statement level triggers (execute once per statement) and row level triggers (execute once per row). Row level triggers use FOR EACH ROW
clause. A trigger may fire BEFORE
, AFTER
, or INSTEAD OF
and INSERT
, DELETE
, or UPDATE
event.
Triggers can be created in MySQL and SQL Server. The trigger syntax varies between database systems.