{"id":181,"date":"2018-07-19T06:21:27","date_gmt":"2018-07-19T06:21:27","guid":{"rendered":"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=181"},"modified":"2018-08-01T10:09:58","modified_gmt":"2018-08-01T10:09:58","slug":"xml-database","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/chapter\/xml-database\/","title":{"rendered":"XML Database"},"content":{"raw":"&nbsp;\r\n\r\n<strong>Introduction<\/strong>\r\n\r\n&nbsp;\r\n\r\nXML: Extensible Markup Language.\r\n\r\nDefined by the WWW Consortium (W3C).\r\n\r\nDerived from SGML (Standard Generalized Markup Language), but simpler to use than HTML .\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-184 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-80.png\" alt=\"\" width=\"613\" height=\"270\" \/><\/p>\r\n<p style=\"text-align: justify\">Documents have tags giving extra information about sections of the document.<\/p>\r\n<p style=\"text-align: justify\">E.g. &lt;title&gt; XML &lt;\/title&gt; &lt;slide&gt; Introduction \u2026&lt;\/slide&gt;<\/p>\r\n<p style=\"text-align: justify\"><strong>Extensible<\/strong>, unlike HTML<\/p>\r\n<p style=\"text-align: justify\">Users can add new tags, and <em>separately<\/em> specify how the tag should be handled for display.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-185 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-81.png\" alt=\"\" width=\"180\" height=\"179\" \/><\/p>\r\n<p style=\"text-align: justify\">The ability to specify new tags, and to create nested tag structures make XML a great way to exchange <strong>data<\/strong>, not just documents.<\/p>\r\n<p style=\"text-align: justify\">Much of the use of XML has been in data exchange applications, not as a replacement for HTML.<\/p>\r\n<p style=\"text-align: justify\">Tags make data (relatively) self-documenting.<\/p>\r\n&nbsp;\r\n\r\n&lt;university&gt;\r\n\r\n&lt;department&gt;\r\n\r\n&lt;dept_name&gt; CSE &lt;\/dept_name&gt;\r\n\r\n&lt;faculty&gt; 50 &lt;\/faculty&gt;\r\n\r\n&lt;students&gt; 500 &lt;\/students&gt;\r\n\r\n&lt;\/department&gt;\r\n\r\n&lt;course&gt;\r\n\r\n&lt;course_code&gt; CS8204 &lt;\/course_id&gt;\r\n\r\n&lt;title&gt; DBMS &lt;\/title&gt;\r\n\r\n&lt;dept_name&gt; CSE &lt;\/dept_name&gt;\r\n\r\n&lt;credits&gt; 4 &lt;\/credits&gt;\r\n\r\n&lt;\/course&gt;\r\n\r\n&lt;\/university&gt;.\r\n<ul>\r\n \t<li>Data interchange is critical in today\u2019s networked world<\/li>\r\n \t<li>Examples:<\/li>\r\n \t<li>Banking: funds transfer<\/li>\r\n \t<li>Order processing (especially inter-company orders)<\/li>\r\n \t<li>Scientific data<\/li>\r\n \t<li>Chemistry: ChemML, \u2026<\/li>\r\n \t<li>Genetics: BSML (Bio-Sequence Markup Language)<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-186 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-82.png\" alt=\"\" width=\"583\" height=\"149\" \/><\/p>\r\n\r\n<ul>\r\n \t<li>Each application area has its own set of standards for representing information.<\/li>\r\n \t<li>\u00a0XML has become the basis for all new generation data interchange formats.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-187 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-83.png\" alt=\"\" width=\"454\" height=\"276\" \/><\/p>\r\n\r\n<ul>\r\n \t<li>XML is better than relational tuples as a data-exchange format.<\/li>\r\n \t<li>Unlike relational tuples, XML data is self-documenting due to presence of tags.<\/li>\r\n \t<li>Non-rigid format: tags can be added.<\/li>\r\n \t<li>\u00a0Allows nested structures.<\/li>\r\n \t<li>\u00a0Wide acceptance, not only in database systems, but also in browsers, tools, and applications.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-188 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-84.png\" alt=\"\" width=\"420\" height=\"173\" \/><\/p>\r\n<strong>Tag<\/strong>: label for a section of data\r\n\r\n&nbsp;\r\n\r\n<strong>Element<\/strong>: section of data beginning with &lt;<em>tagname<\/em>&gt; and ending with matching &lt;\/<em>tagname<\/em>&gt;\r\n\r\nElements must be properly nested\r\n\r\nProper nesting\r\n\r\n&lt;course&gt; \u2026 &lt;title&gt;\u00a0 \u2026. &lt;\/title&gt; &lt;\/course&gt;\r\n\r\nImproper nesting\r\n\r\n&lt;course&gt; \u2026 &lt;title&gt;\u00a0 \u2026. &lt;\/course&gt; &lt;\/title&gt;\r\n<p style=\"text-align: justify\">Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element.<\/p>\r\nEvery document must have a single top-level element\r\n<ul>\r\n \t<li>Nesting of data is useful in data transfer.<\/li>\r\n \t<li>Example: elements representing <em>student<\/em> nested within an <em>department<\/em><\/li>\r\n \t<li>Nesting is appropriate when transferring data.<\/li>\r\n \t<li>External application does not have direct access to data referenced by a foreign key.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-189 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-85.png\" alt=\"\" width=\"321\" height=\"182\" \/><\/p>\r\n\r\n<ul>\r\n \t<li style=\"text-align: justify\">Nesting is not supported, or discouraged, in relational databases.<\/li>\r\n \t<li style=\"text-align: justify\">With multiple orders, customer name and address are stored redundantly.<\/li>\r\n \t<li style=\"text-align: justify\">normalization replaces nested structures in each order by foreign key into table storing customer name and address information.<\/li>\r\n \t<li style=\"text-align: justify\">Nesting is supported in object-relational databases.<\/li>\r\n \t<li style=\"text-align: justify\">Elements can have <strong style=\"text-align: initial;font-size: 1em\">attributes.<\/strong><span style=\"text-align: initial;font-size: 1em\"> &lt;course course_code= \u201cCS8204\u201d&gt;<\/span><\/li>\r\n<\/ul>\r\n&lt;title&gt; DBMS &lt;\/title&gt;\r\n\r\n&lt;dept_name&gt; CSE &lt;\/dept_name&gt; &lt;credits&gt; 3 &lt;\/credits&gt;\r\n\r\n&lt;\/course&gt;\r\n<div>\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0Attributes are specified by <em>name-value<\/em> pairs inside the starting tag of an element.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0An element may have several attributes, but each attribute name can only occur once<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 &lt;course\u00a0 course_code = \u201cCS8204\u201d\u00a0 credits=\u201c3\u201d&gt;<\/p>\r\n<p style=\"text-align: justify\">In the context of documents, attributes are part of markup, while sub-element contents are part of the basic document contents.<\/p>\r\n<p style=\"text-align: justify\">In the context of data representation, the difference is unclear and may be confusing.<\/p>\r\n<p style=\"text-align: justify\">Same information can be represented in two ways<\/p>\r\n<p style=\"text-align: justify\">&lt;course course_code= \u201cCS8204\u201d&gt;<\/p>\r\n...\r\n\r\n&lt;\/course&gt;\r\n\r\n&lt;course&gt;\r\n\r\n&lt;course_code&gt;CS8204&lt;\/course_code&gt; \u2026\r\n\r\n&lt;\/course&gt;\r\n\r\n<\/div>\r\n<ul>\r\n \t<li style=\"text-align: justify\">XML data has to be exchanged between organizations.<\/li>\r\n \t<li style=\"text-align: justify\">Same tag name may have different meaning in different organizations, causing confusion on exchanged documents.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Specifying a unique string as an element name avoids confusion.<\/li>\r\n \t<li style=\"text-align: justify\">Better solution: use unique-name:element-name.<\/li>\r\n \t<li style=\"text-align: justify\">Avoid using long unique names all over document by using XML Namespaces<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 &lt;university xmlns:anna_univ=\u201chttp:\/\/www.annauniv.edu\u201d&gt;\u2026<\/p>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0&lt;annauniv:course&gt;<\/p>\r\n<p style=\"text-align: justify\">\u00a0 &lt;annauniv:course_code&gt; CS8204 &lt;\/annauniv:course_code&gt; &lt;annauniv:title&gt; DBMS &lt;\/annauniv:title&gt; &lt;annauniv:dept_name&gt; CSE &lt;\/annauniv:dept_name&gt; &lt;annauniv:credits&gt; 3 &lt;\/annauniv:credits&gt;<\/p>\r\n<p style=\"text-align: justify\">&lt;\/annauniv:course&gt;<\/p>\r\n\u2026\r\n\r\n&lt;\/university&gt;\r\n\r\n&nbsp;\r\n\r\nElements without sub-elements or text content can be abbreviated by ending the start tag with a \/&gt; and deleting the end tag\r\n\r\n&lt;course course_code=\u201cCS8204\u201d Title=\u201cDBMS\u201d dept_name = \u201cCSE\u201d credits=\u201c3\u201d \/&gt;\r\n\r\nTo store string data that may contain tags, without the tags being interpreted as sub-elements, use CDATA as below\r\n\r\n&lt;![CDATA[&lt;course&gt; \u2026 &lt;\/course&gt;]]&gt;\r\n\r\nHere, &lt;course&gt; and &lt;\/course&gt; are treated as just strings CDATA stands for \u201ccharacter data\u201d\r\n<div>\r\n<ul>\r\n \t<li>\u00a0Database schemas constrain what information can be stored, and the data types of stored values.<\/li>\r\n \t<li>\u00a0XML documents are not required to have an associated schema.<\/li>\r\n \t<li>\u00a0However, schemas are very important for XML data exchange.<\/li>\r\n \t<li>Otherwise, a site cannot automatically interpret data received from another site.<\/li>\r\n \t<li>Two mechanisms for specifying XML schema.<\/li>\r\n<\/ul>\r\n<strong>Document Type Definition (DTD)<\/strong>\r\n\r\n&nbsp;\r\n\r\nWidely used\r\n\r\n&nbsp;\r\n\r\n<strong>XML Schema<\/strong>\r\n\r\n<\/div>\r\n<ul>\r\n \t<li>Newer, increasing use<\/li>\r\n \t<li>The type of an XML document can be specified using a DTD.<\/li>\r\n \t<li>DTD constraints structure of XML data.<\/li>\r\n \t<li>What elements can occur?<\/li>\r\n \t<li>What attributes can\/must an element have?<\/li>\r\n \t<li>What subelements can\/must occur inside each element, and how many times?<\/li>\r\n \t<li>DTD does not constrain data types.<\/li>\r\n \t<li>All values represented as strings in XML.<\/li>\r\n \t<li>DTD syntax.<\/li>\r\n \t<li>&lt;!ELEMENT element (subelements-specification) &gt;<\/li>\r\n \t<li>&lt;!ATTLIST element (attributes)<\/li>\r\n \t<li>Sub-elements can be specified as<\/li>\r\n \t<li>names of elements, or<\/li>\r\n \t<li>#PCDATA (parsed character data), i.e., character strings<\/li>\r\n \t<li>EMPTY (no subelements) or ANY (anything can be a subelement)<\/li>\r\n \t<li>Example<\/li>\r\n \t<li>&lt;! ELEMENT department (dept_name building, budget)&gt; &lt;! ELEMENT dept_name (#PCDATA)&gt;<\/li>\r\n \t<li>! ELEMENT budget (#PCDATA)&gt;<\/li>\r\n \t<li>Subelement specification may have regular expressions<\/li>\r\n<\/ul>\r\n&lt;!ELEMENT university ( ( department | course | faculty | teaches )+)&gt;\r\n<ul>\r\n \t<li>Notation:<\/li>\r\n \t<li>\u201c|\u201d -\u00a0 alternatives<\/li>\r\n \t<li>\u201c+\u201d -\u00a0 1 or more occurrences<\/li>\r\n \t<li>\u00a0\u201c*\u201d -\u00a0 0 or more occurrences<\/li>\r\n \t<li>An element can have at most one attribute of type ID.<\/li>\r\n \t<li>The ID attribute value of each element in an XML document must be distinct.<\/li>\r\n \t<li>Thus, the ID attribute value is an object identifier.<\/li>\r\n \t<li>An attribute of type IDREF must contain the ID value of an element in the same document.<\/li>\r\n \t<li>An attribute of type IDREFS contains a set of (0 or more) ID values. Each ID value must contain the ID value of an element in the same document.<\/li>\r\n<\/ul>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Example<\/strong>\r\n<div>\r\n\r\n\u00a0 \u00a0 \u00a0&lt;university&gt;\r\n\r\n&lt;department dept_name=\u201cCSE\u201d&gt;\r\n\r\n&lt;faculty&gt; 50 &lt;\/faculty&gt;\r\n\r\n&lt;students&gt; 500 &lt;\/students&gt;\r\n\r\n&lt;\/department&gt;\r\n\r\n&lt;course course_code=\u201cCS8204\u201d dept_name=\u201cCSE\u201d course_incharge=\u201c54783\u201d&gt; &lt;title&gt; DBMS &lt;\/title&gt;\r\n\r\n&lt;credits&gt; 3 &lt;\/credits&gt;\r\n\r\n&lt;\/course&gt;\r\n\r\n\u2026.\r\n\r\n&lt;course_incharge staff_id=\u201c54783\u201d dept_name=\u201cCSE\u201d&gt; &lt;name&gt; Arvind &lt;\/name&gt;\r\n\r\n&lt;salary&gt; 75000 &lt;\/salary&gt;\r\n\r\n&lt;\/course_incharge&gt;\r\n\r\n\u2026.\r\n\r\n&lt;\/university&gt;\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XML Schema<\/strong>\r\n<div>\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0 XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0Typing of values<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0Eg. integer, string, etc<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0Also, constraints on min\/max values<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0User-defined, complex types<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0Many more features, including<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0uniqueness and foreign key constraints, inheritance<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0XML Schema is itself specified in XML syntax, unlike DTDs<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0More-standard representation, but verbose<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0XML Scheme is integrated with namespaces<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0BUT: XML Schema is significantly more complicated than DTDs.<\/li>\r\n<\/ul>\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Rationale for XML in Databases<\/strong>\r\n<div>\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0 There are a number of reasons to directly specify data in XML or other document formats such as JSON.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 For XML in particular, they include:<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 An enterprise may have a lot of XML in an existing standard format.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Data may need to be exposed or ingested as XML, so using another format such as relational forces double-modeling of the data.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0XML is very well suited to sparse data, deeply nested data and mixed content (such as text with embedded markup tags).<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0XML is human readable whereas relational tables require expertise to access.<\/li>\r\n \t<li style=\"text-align: justify\">Metadata is often available as XML.<\/li>\r\n \t<li style=\"text-align: justify\">Semantic web data is available as RDF\/XML.<\/li>\r\n<\/ul>\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XML in Databases<\/strong>\r\n\r\n&nbsp;\r\n<div>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 Steve O'Connell gives one reason for the use of XML in databases: the increasingly common use of XML for data transport hich has meant that \"data is extracted from databases and put into XML documents and vice-versa\u201d.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">In content-based applications, the ability of the native XML database also minimizes the need for extraction or entry of metadata to support searching and navigation.<\/p>\r\n&nbsp;\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 Querying and Transforming XML Data<\/strong>\r\n<ul>\r\n \t<li>Translation of information from one XML schema to another<\/li>\r\n \t<li>Querying on XML data<\/li>\r\n \t<li>Above two are closely related, and handled by the same tools<\/li>\r\n \t<li>Standard XML querying\/translation languages<\/li>\r\n \t<li>XPath<\/li>\r\n \t<li>Simple language consisting of path expressions<\/li>\r\n \t<li>XSLT<\/li>\r\n \t<li>Simple language designed for translation from XML to XML and XML to HTML<\/li>\r\n \t<li>XQuery<\/li>\r\n \t<li>An XML query language with a rich set of features<\/li>\r\n<\/ul>\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">Tree Model of XML Data<\/strong>\r\n<div>\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0Query and transformation languages are based on a <strong>tree model<\/strong> of XML data.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0An XML document is modeled as a tree, with <strong>nodes<\/strong> corresponding to elements and attributes.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Element nodes have child nodes, which can be attributes or subelements.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Text in an element is modeled as a text node child of the element<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Children of a node are ordered according to their order in the XML document.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Element and attribute nodes (except for the root node) have a single parent, which is an element node.<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0The root node has a single child, which is the root element of the document.<\/li>\r\n<\/ul>\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0XPath\u00a0<\/strong>\r\n<ul>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">XPath is used to address (select) parts of documents using <\/span><strong style=\"text-align: initial;font-size: 1em\">path<\/strong> <strong style=\"text-align: initial;font-size: 1em\">expressions<\/strong><\/li>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">A path expression is a sequence of steps separated by \u201c\/\u201d<\/span><\/li>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">\u00a0Think of file names in a directory hierarchy<\/span><\/li>\r\n \t<li><span style=\"text-align: initial;font-size: 1em\">Result of path expression: set of values that along with their containing elements\/attributes match the specified path<\/span><\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 E.g. \/university\/course_incharge\/name evaluated on the university data we saw earlier returns\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0&lt;name&gt;Arvind&lt;\/name&gt;<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0&lt;name&gt;Balu&lt;\/name&gt;<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0E.g.\/university\/course_incharge\/name\/text( )<\/span><\/p>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0returns the same names, but without the enclosing tags Arvind, Balu<\/span><\/p>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0XQuery<\/strong>\r\n<div>\r\n<ul>\r\n \t<li>XQuery is a general purpose query language for XML data<\/li>\r\n \t<li>XQuery is derived from the Quilt query language, which itself borrows from SQL, XQL and XML-QL<\/li>\r\n \t<li>XQuery uses a<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 \u00a0for \u2026 let \u2026 where \u2026 order by \u2026result <\/strong>\u2026\r\n\r\nsyntax\r\n\r\n<strong>for<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00f3 SQL <strong>from<\/strong>\r\n\r\n<strong>where <\/strong>\u00f3 SQL<strong> where<\/strong>\r\n\r\n<strong>order by <\/strong>\u00f3 SQL<strong> order by<\/strong>\r\n\r\n<strong>result <\/strong>\u00f3 SQL<strong> select<\/strong>\r\n\r\n<strong>let <\/strong>allows temporary variables, and has no equivalent in SQL\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0<\/strong>\r\n\r\n<strong> \u00a0XSLT<\/strong>\r\n<ul>\r\n \t<li>\u00a0A <strong>stylesheet<\/strong> stores formatting options for a document, usually separately from document.<\/li>\r\n \t<li>\u00a0E.g. an HTML style sheet may specify font colors and sizes for headings, etc.<\/li>\r\n \t<li>\u00a0The <strong>XML Stylesheet Language (XSL)<\/strong> was originally designed for generating HTML from XML.<\/li>\r\n \t<li>\u00a0XSLT is a general-purpose transformation language.<\/li>\r\n \t<li>\u00a0Can translate XML to XML, and XML to HTML.<\/li>\r\n \t<li>\u00a0XSLT transformations are expressed using rules called <strong>templates.<\/strong><\/li>\r\n \t<li>\u00a0Templates combine selection using XPath with construction of results.<\/li>\r\n<\/ul>\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Application Program Interface<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nThere are two standard application program interfaces to XML data:\r\n\r\n<strong>\u00a0 \u00a0 SAX <\/strong>(Simple API for XML)\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0Based on parser model, user provides event handlers for parsing events<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 \u00a0E.g. start of element, end of element<\/li>\r\n \t<li style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0 DOM <\/strong><span style=\"text-align: initial;font-size: 1em\">(Document Object Model)<\/span><\/li>\r\n \t<li style=\"text-align: justify\">\u00a0\u00a0<strong style=\"text-align: initial;font-size: 1em\">XML <\/strong><span style=\"text-align: initial;font-size: 1em\">data is parsed into a tree representation<\/span><\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Variety of functions provided for traversing the DOM tree<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0E.g.: Java DOM API provides Node class with methods getParentNode( ), getFirstChild( ), getNextSibling( ) getElementsByTagName( ), \u2026<\/li>\r\n \t<li style=\"text-align: justify\">Also provides functions for updating DOM tree<\/li>\r\n<\/ul>\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 Storage of XML Data<\/strong>\r\n<div>\r\n<ul>\r\n \t<li>\u00a0 \u00a0XML data can be stored in<\/li>\r\n \t<li>\u00a0 \u00a0Non-relational data stores<\/li>\r\n \t<li>\u00a0 \u00a0Flat files<\/li>\r\n \t<li>\u00a0 \u00a0Natural for storing XML<\/li>\r\n \t<li>\u00a0 \u00a0But has all problems discussed in Chapter 1 (no concurrency, no recovery, \u2026)<\/li>\r\n \t<li>\u00a0 \u00a0XML database<\/li>\r\n \t<li>\u00a0 \u00a0Database built specifically for storing XML data, supporting DOM model and declarative querying<\/li>\r\n \t<li>\u00a0 \u00a0Currently no commercial-grade systems<\/li>\r\n \t<li>\u00a0 \u00a0Relational databases<\/li>\r\n \t<li>\u00a0 \u00a0Data must be translated into relational form<\/li>\r\n \t<li>\u00a0 \u00a0Advantage: mature database systems<\/li>\r\n \t<li>\u00a0 \u00a0Disadvantages: overhead of translating data and queries<\/li>\r\n<\/ul>\r\n<\/div>\r\n<strong>\u00a0 \u00a0 Storage of XML in Relational Databases<\/strong>\r\n<ul>\r\n \t<li>Alternative Representations :<\/li>\r\n \t<li>String Representation<\/li>\r\n \t<li>Tree Representation<\/li>\r\n \t<li>Map to relations<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"alignnone size-full wp-image-190\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-86.png\" alt=\"\" width=\"657\" height=\"189\" \/><\/p>\r\n\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0 String Representation<\/strong>\r\n<ul>\r\n \t<li>Store each top level element as a string field of a tuple in a relational database.<\/li>\r\n \t<li>Use a single relation to store all elements, or<\/li>\r\n \t<li>Use a separate relation for each top-level element type.<\/li>\r\n \t<li>E.g.\u00a0 account, customer, depositor relations.<\/li>\r\n \t<li>Each with a string-valued attribute to store the element.<\/li>\r\n \t<li>Indexing:<\/li>\r\n \t<li style=\"text-align: justify\">Store values of subelements\/attributes to be indexed as extra fields of the relation, and build indices on these fields.<\/li>\r\n \t<li>E.g. customer_name or account_number.<\/li>\r\n \t<li>Some database systems support <strong>function indices,<\/strong> which use the result of a function as the key value.<\/li>\r\n \t<li>The function should return the value of the required subelement\/attribute.<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 \u00a0 Benefits:<\/strong>\r\n\r\n<\/div>\r\n<div>\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0 Can store any XML data even without DTD<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0 As long as there are many top-level elements in a document, strings are small compared to full document<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Allows fast access to individual elements.<\/li>\r\n<\/ul>\r\n<strong>\u00a0 Drawback:<\/strong>\r\n<ul>\r\n \t<li>\u00a0Need to parse strings to access values inside the elements<\/li>\r\n \t<li>\u00a0P<span style=\"font-size: 1em\">arsing is slow.<\/span><\/li>\r\n \t<li><strong>Tree representation: <\/strong>model XML data as tree and store using relations <em>nodes(id, parent_id, type, label, value)<\/em><\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-191 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-87.png\" alt=\"\" width=\"515\" height=\"169\" \/><\/p>\r\n\r\n<ul>\r\n \t<li>Each element\/attribute is given a unique identifier<\/li>\r\n \t<li>Type indicates element\/attribute<\/li>\r\n \t<li>Label specifies the tag name of the element\/name of attribute<\/li>\r\n \t<li>Value is the text value of the element\/attribute<\/li>\r\n \t<li>Can add an extra attribute <em>position<\/em> to record ordering of children<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 Benefit:<\/strong>\r\n<ul>\r\n \t<li>Can store any XML data, even without DTD.<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 \u00a0Drawbacks:<\/strong>\r\n<ul>\r\n \t<li style=\"text-align: justify\">Data is broken up into too many pieces, increasing space overheads.<\/li>\r\n \t<li style=\"text-align: justify\">Even simple queries require a large number of joins, which can be slow.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\"><strong>\u00a0 \u00a0 \u00a0Mapping XML data to Relations<\/strong><\/p>\r\n\r\n<ul>\r\n \t<li style=\"text-align: justify\">Relation created for each element type whose schema is known:<\/li>\r\n \t<li style=\"text-align: justify\">An id attribute to store a unique id for each element.<\/li>\r\n \t<li style=\"text-align: justify\">A relation attribute corresponding to each element attribute.<\/li>\r\n \t<li style=\"text-align: justify\">A parent_id attribute to keep track of parent element.<\/li>\r\n \t<li style=\"text-align: justify\">As in the tree representation.<\/li>\r\n \t<li style=\"text-align: justify\">Position information (ith child) can be store too.<\/li>\r\n \t<li style=\"text-align: justify\">All sub-elements that occur only once can become relation attributes.<\/li>\r\n \t<li style=\"text-align: justify\">For text-valued sub-elements, store the text as attribute value.<\/li>\r\n \t<li style=\"text-align: justify\">For complex sub-elements, can store the id of the sub-element.<\/li>\r\n \t<li style=\"text-align: justify\">Sub-elements that can occur multiple times represented in a separate table.<\/li>\r\n \t<li style=\"text-align: justify\">Similar to handling of multivalued attributes when converting ER diagrams to tables.<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 Storing XML Data in Relational Systems<\/strong>\r\n<ul>\r\n \t<li style=\"text-align: justify\">Applying above ideas to department elements in university-1 schema, with nested course elements, we get\u00a0<em style=\"text-align: initial;font-size: 1em\">department<\/em><span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">id<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> dept_name<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> faculty<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> students<\/em><span style=\"text-align: initial;font-size: 1em\">)\u00a0<\/span><em style=\"text-align: initial;font-size: 1em\">course<\/em><span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">parent id<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> course_code<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> dept_name<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> title<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> credits<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span><\/li>\r\n \t<li style=\"text-align: justify\"><strong>Publishing<\/strong>: process of converting relational data to an XML format<\/li>\r\n \t<li style=\"text-align: justify\"><strong>Shredding<\/strong>: process of converting an XML document into a set of tuples to be inserted into one or more relations<\/li>\r\n \t<li style=\"text-align: justify\">XML-enabled database systems support automated publishing and shredding<\/li>\r\n \t<li style=\"text-align: justify\">Many systems offer <em>native storage<\/em> of XML data using the <strong>xml<\/strong> data type. Special internal data structures and indices are used for efficiency<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 \u00a0XML Enabled databases<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">XML enabled databases typically offer one or more of the following approaches to storing XML within the traditional relational structure:<\/p>\r\n\r\n<ul>\r\n \t<li>XML is stored into a CLOB (Character Large OBject).<\/li>\r\n \t<li>XML is `shredded` into a series of Tables based on a Schema.<\/li>\r\n \t<li>XML is stored into a native XML Type as defined by ISO Standard 9075-14.<\/li>\r\n<\/ul>\r\nRDBMS that support the ISO XML Type are:\r\n<ul>\r\n \t<li>IBM DB2 (pureXML)<\/li>\r\n \t<li>Microsoft SQL Server.<\/li>\r\n \t<li>Oracle Database.<\/li>\r\n \t<li>PostgreSQL<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 XML Enabled databases<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">XML enabled databases typically offer one or more of the following approaches to storing XML within the traditional relational structure:<\/p>\r\n\r\n<ul>\r\n \t<li>XML is stored into a CLOB (Character Large OBject).<\/li>\r\n \t<li>XML is `shredded` into a series of Tables based on a Schema.<\/li>\r\n \t<li>XML is stored into a native XML Type as defined by ISO Standard 9075-14.<\/li>\r\n<\/ul>\r\nRDBMS that support the ISO XML Type are:\r\n<ul>\r\n \t<li>IBM DB2 (pureXML)<\/li>\r\n \t<li>Microsoft SQL Server.<\/li>\r\n \t<li>Oracle Database.<\/li>\r\n \t<li>PostgreSQL<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 \u00a0Key Features<\/strong>\r\n<ul>\r\n \t<li>Has an XML document as at least one fundamental unit of (logical) storage, just as a relational database has a Row in a table as a fundamental unit of (logical) storage.<\/li>\r\n \t<li>Need not have any particular underlying physical storage model.<\/li>\r\n \t<li>For example, NXDs can use optimized, proprietary storage formats.<\/li>\r\n \t<li>This is a key aspect of XML databases.<\/li>\r\n \t<li>Managing XML as large strings is inefficient due to the extra markup in XML.<\/li>\r\n \t<li>Compressing and indexing XML allows the illusion of directly accessing, querying and transforming XML while gaining the performance advantages of working with optimized binary tree structures.<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 \u00a0Language Features<\/strong>\r\n\r\n<img class=\"size-full wp-image-192 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88.png\" alt=\"\" width=\"882\" height=\"343\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>Supported API<\/strong>\r\n\r\n<\/div>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-193 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89.png\" alt=\"\" width=\"785\" height=\"267\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>XML Database Applications<\/strong>\r\n<ul>\r\n \t<li>Storing and exchanging data with complex structures<\/li>\r\n \t<li>g. Open Document Format (ODF) format standard for storing Open Office and Office Open XML (OOXML) Format standard for storing Microsoft Office documents<\/li>\r\n \t<li>Numerous other standards for a variety of applications<\/li>\r\n \t<li>ChemML, MathML<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-194 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-90.png\" alt=\"\" width=\"476\" height=\"164\" \/><\/p>\r\n\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 XML Database Applications<\/strong>\r\n\r\n<\/div>\r\nStandard for data exchange for Web services\r\n<ul>\r\n \t<li>remote method invocation over HTTP protocol Data mediation<\/li>\r\n \t<li>Common data representation format to bridge different systems<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-195 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-91.png\" alt=\"\" width=\"332\" height=\"200\" \/><\/p>\r\n\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0 Summary<\/strong>\r\n\r\n<\/div>\r\n<ul>\r\n \t<li>\u00a0Introduction to XML<\/li>\r\n \t<li>XML Syntax<\/li>\r\n \t<li>Querying and Transforming XML data<\/li>\r\n \t<li>Different representations of XML in relational data<\/li>\r\n \t<li>Storing XML data in Relational Systems<\/li>\r\n \t<li>XML Database Applications<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-196 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-92.png\" alt=\"\" width=\"631\" height=\"361\" \/><\/p>","rendered":"<p>&nbsp;<\/p>\n<p><strong>Introduction<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>XML: Extensible Markup Language.<\/p>\n<p>Defined by the WWW Consortium (W3C).<\/p>\n<p>Derived from SGML (Standard Generalized Markup Language), but simpler to use than HTML .<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-184 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-80.png\" alt=\"\" width=\"613\" height=\"270\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-80.png 613w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-80-300x132.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-80-65x29.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-80-225x99.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-80-350x154.png 350w\" sizes=\"auto, (max-width: 613px) 100vw, 613px\" \/><\/p>\n<p style=\"text-align: justify\">Documents have tags giving extra information about sections of the document.<\/p>\n<p style=\"text-align: justify\">E.g. &lt;title&gt; XML &lt;\/title&gt; &lt;slide&gt; Introduction \u2026&lt;\/slide&gt;<\/p>\n<p style=\"text-align: justify\"><strong>Extensible<\/strong>, unlike HTML<\/p>\n<p style=\"text-align: justify\">Users can add new tags, and <em>separately<\/em> specify how the tag should be handled for display.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-185 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-81.png\" alt=\"\" width=\"180\" height=\"179\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-81.png 180w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-81-150x150.png 150w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-81-65x65.png 65w\" sizes=\"auto, (max-width: 180px) 100vw, 180px\" \/><\/p>\n<p style=\"text-align: justify\">The ability to specify new tags, and to create nested tag structures make XML a great way to exchange <strong>data<\/strong>, not just documents.<\/p>\n<p style=\"text-align: justify\">Much of the use of XML has been in data exchange applications, not as a replacement for HTML.<\/p>\n<p style=\"text-align: justify\">Tags make data (relatively) self-documenting.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;university&gt;<\/p>\n<p>&lt;department&gt;<\/p>\n<p>&lt;dept_name&gt; CSE &lt;\/dept_name&gt;<\/p>\n<p>&lt;faculty&gt; 50 &lt;\/faculty&gt;<\/p>\n<p>&lt;students&gt; 500 &lt;\/students&gt;<\/p>\n<p>&lt;\/department&gt;<\/p>\n<p>&lt;course&gt;<\/p>\n<p>&lt;course_code&gt; CS8204 &lt;\/course_id&gt;<\/p>\n<p>&lt;title&gt; DBMS &lt;\/title&gt;<\/p>\n<p>&lt;dept_name&gt; CSE &lt;\/dept_name&gt;<\/p>\n<p>&lt;credits&gt; 4 &lt;\/credits&gt;<\/p>\n<p>&lt;\/course&gt;<\/p>\n<p>&lt;\/university&gt;.<\/p>\n<ul>\n<li>Data interchange is critical in today\u2019s networked world<\/li>\n<li>Examples:<\/li>\n<li>Banking: funds transfer<\/li>\n<li>Order processing (especially inter-company orders)<\/li>\n<li>Scientific data<\/li>\n<li>Chemistry: ChemML, \u2026<\/li>\n<li>Genetics: BSML (Bio-Sequence Markup Language)<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-186 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-82.png\" alt=\"\" width=\"583\" height=\"149\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-82.png 583w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-82-300x77.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-82-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-82-225x58.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-82-350x89.png 350w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/p>\n<ul>\n<li>Each application area has its own set of standards for representing information.<\/li>\n<li>\u00a0XML has become the basis for all new generation data interchange formats.<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-187 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-83.png\" alt=\"\" width=\"454\" height=\"276\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-83.png 454w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-83-300x182.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-83-65x40.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-83-225x137.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-83-350x213.png 350w\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" \/><\/p>\n<ul>\n<li>XML is better than relational tuples as a data-exchange format.<\/li>\n<li>Unlike relational tuples, XML data is self-documenting due to presence of tags.<\/li>\n<li>Non-rigid format: tags can be added.<\/li>\n<li>\u00a0Allows nested structures.<\/li>\n<li>\u00a0Wide acceptance, not only in database systems, but also in browsers, tools, and applications.<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-188 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-84.png\" alt=\"\" width=\"420\" height=\"173\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-84.png 420w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-84-300x124.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-84-65x27.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-84-225x93.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-84-350x144.png 350w\" sizes=\"auto, (max-width: 420px) 100vw, 420px\" \/><\/p>\n<p><strong>Tag<\/strong>: label for a section of data<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Element<\/strong>: section of data beginning with &lt;<em>tagname<\/em>&gt; and ending with matching &lt;\/<em>tagname<\/em>&gt;<\/p>\n<p>Elements must be properly nested<\/p>\n<p>Proper nesting<\/p>\n<p>&lt;course&gt; \u2026 &lt;title&gt;\u00a0 \u2026. &lt;\/title&gt; &lt;\/course&gt;<\/p>\n<p>Improper nesting<\/p>\n<p>&lt;course&gt; \u2026 &lt;title&gt;\u00a0 \u2026. &lt;\/course&gt; &lt;\/title&gt;<\/p>\n<p style=\"text-align: justify\">Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element.<\/p>\n<p>Every document must have a single top-level element<\/p>\n<ul>\n<li>Nesting of data is useful in data transfer.<\/li>\n<li>Example: elements representing <em>student<\/em> nested within an <em>department<\/em><\/li>\n<li>Nesting is appropriate when transferring data.<\/li>\n<li>External application does not have direct access to data referenced by a foreign key.<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-189 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-85.png\" alt=\"\" width=\"321\" height=\"182\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-85.png 321w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-85-300x170.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-85-65x37.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-85-225x128.png 225w\" sizes=\"auto, (max-width: 321px) 100vw, 321px\" \/><\/p>\n<ul>\n<li style=\"text-align: justify\">Nesting is not supported, or discouraged, in relational databases.<\/li>\n<li style=\"text-align: justify\">With multiple orders, customer name and address are stored redundantly.<\/li>\n<li style=\"text-align: justify\">normalization replaces nested structures in each order by foreign key into table storing customer name and address information.<\/li>\n<li style=\"text-align: justify\">Nesting is supported in object-relational databases.<\/li>\n<li style=\"text-align: justify\">Elements can have <strong style=\"text-align: initial;font-size: 1em\">attributes.<\/strong><span style=\"text-align: initial;font-size: 1em\"> &lt;course course_code= \u201cCS8204\u201d&gt;<\/span><\/li>\n<\/ul>\n<p>&lt;title&gt; DBMS &lt;\/title&gt;<\/p>\n<p>&lt;dept_name&gt; CSE &lt;\/dept_name&gt; &lt;credits&gt; 3 &lt;\/credits&gt;<\/p>\n<p>&lt;\/course&gt;<\/p>\n<div>\n<ul>\n<li style=\"text-align: justify\">\u00a0Attributes are specified by <em>name-value<\/em> pairs inside the starting tag of an element.<\/li>\n<li style=\"text-align: justify\">\u00a0An element may have several attributes, but each attribute name can only occur once<\/li>\n<\/ul>\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 &lt;course\u00a0 course_code = \u201cCS8204\u201d\u00a0 credits=\u201c3\u201d&gt;<\/p>\n<p style=\"text-align: justify\">In the context of documents, attributes are part of markup, while sub-element contents are part of the basic document contents.<\/p>\n<p style=\"text-align: justify\">In the context of data representation, the difference is unclear and may be confusing.<\/p>\n<p style=\"text-align: justify\">Same information can be represented in two ways<\/p>\n<p style=\"text-align: justify\">&lt;course course_code= \u201cCS8204\u201d&gt;<\/p>\n<p>&#8230;<\/p>\n<p>&lt;\/course&gt;<\/p>\n<p>&lt;course&gt;<\/p>\n<p>&lt;course_code&gt;CS8204&lt;\/course_code&gt; \u2026<\/p>\n<p>&lt;\/course&gt;<\/p>\n<\/div>\n<ul>\n<li style=\"text-align: justify\">XML data has to be exchanged between organizations.<\/li>\n<li style=\"text-align: justify\">Same tag name may have different meaning in different organizations, causing confusion on exchanged documents.<\/li>\n<li style=\"text-align: justify\">\u00a0Specifying a unique string as an element name avoids confusion.<\/li>\n<li style=\"text-align: justify\">Better solution: use unique-name:element-name.<\/li>\n<li style=\"text-align: justify\">Avoid using long unique names all over document by using XML Namespaces<\/li>\n<\/ul>\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 &lt;university xmlns:anna_univ=\u201chttp:\/\/www.annauniv.edu\u201d&gt;\u2026<\/p>\n<p style=\"text-align: justify\">\u00a0 \u00a0&lt;annauniv:course&gt;<\/p>\n<p style=\"text-align: justify\">\u00a0 &lt;annauniv:course_code&gt; CS8204 &lt;\/annauniv:course_code&gt; &lt;annauniv:title&gt; DBMS &lt;\/annauniv:title&gt; &lt;annauniv:dept_name&gt; CSE &lt;\/annauniv:dept_name&gt; &lt;annauniv:credits&gt; 3 &lt;\/annauniv:credits&gt;<\/p>\n<p style=\"text-align: justify\">&lt;\/annauniv:course&gt;<\/p>\n<p>\u2026<\/p>\n<p>&lt;\/university&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>Elements without sub-elements or text content can be abbreviated by ending the start tag with a \/&gt; and deleting the end tag<\/p>\n<p>&lt;course course_code=\u201cCS8204\u201d Title=\u201cDBMS\u201d dept_name = \u201cCSE\u201d credits=\u201c3\u201d \/&gt;<\/p>\n<p>To store string data that may contain tags, without the tags being interpreted as sub-elements, use CDATA as below<\/p>\n<p>&lt;![CDATA[&lt;course&gt; \u2026 &lt;\/course&gt;]]&gt;<\/p>\n<p>Here, &lt;course&gt; and &lt;\/course&gt; are treated as just strings CDATA stands for \u201ccharacter data\u201d<\/p>\n<div>\n<ul>\n<li>\u00a0Database schemas constrain what information can be stored, and the data types of stored values.<\/li>\n<li>\u00a0XML documents are not required to have an associated schema.<\/li>\n<li>\u00a0However, schemas are very important for XML data exchange.<\/li>\n<li>Otherwise, a site cannot automatically interpret data received from another site.<\/li>\n<li>Two mechanisms for specifying XML schema.<\/li>\n<\/ul>\n<p><strong>Document Type Definition (DTD)<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Widely used<\/p>\n<p>&nbsp;<\/p>\n<p><strong>XML Schema<\/strong><\/p>\n<\/div>\n<ul>\n<li>Newer, increasing use<\/li>\n<li>The type of an XML document can be specified using a DTD.<\/li>\n<li>DTD constraints structure of XML data.<\/li>\n<li>What elements can occur?<\/li>\n<li>What attributes can\/must an element have?<\/li>\n<li>What subelements can\/must occur inside each element, and how many times?<\/li>\n<li>DTD does not constrain data types.<\/li>\n<li>All values represented as strings in XML.<\/li>\n<li>DTD syntax.<\/li>\n<li>&lt;!ELEMENT element (subelements-specification) &gt;<\/li>\n<li>&lt;!ATTLIST element (attributes)<\/li>\n<li>Sub-elements can be specified as<\/li>\n<li>names of elements, or<\/li>\n<li>#PCDATA (parsed character data), i.e., character strings<\/li>\n<li>EMPTY (no subelements) or ANY (anything can be a subelement)<\/li>\n<li>Example<\/li>\n<li>&lt;! ELEMENT department (dept_name building, budget)&gt; &lt;! ELEMENT dept_name (#PCDATA)&gt;<\/li>\n<li>! ELEMENT budget (#PCDATA)&gt;<\/li>\n<li>Subelement specification may have regular expressions<\/li>\n<\/ul>\n<p>&lt;!ELEMENT university ( ( department | course | faculty | teaches )+)&gt;<\/p>\n<ul>\n<li>Notation:<\/li>\n<li>\u201c|\u201d &#8211;\u00a0 alternatives<\/li>\n<li>\u201c+\u201d &#8211;\u00a0 1 or more occurrences<\/li>\n<li>\u00a0\u201c*\u201d &#8211;\u00a0 0 or more occurrences<\/li>\n<li>An element can have at most one attribute of type ID.<\/li>\n<li>The ID attribute value of each element in an XML document must be distinct.<\/li>\n<li>Thus, the ID attribute value is an object identifier.<\/li>\n<li>An attribute of type IDREF must contain the ID value of an element in the same document.<\/li>\n<li>An attribute of type IDREFS contains a set of (0 or more) ID values. Each ID value must contain the ID value of an element in the same document.<\/li>\n<\/ul>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Example<\/strong><\/p>\n<div>\n<p>\u00a0 \u00a0 \u00a0&lt;university&gt;<\/p>\n<p>&lt;department dept_name=\u201cCSE\u201d&gt;<\/p>\n<p>&lt;faculty&gt; 50 &lt;\/faculty&gt;<\/p>\n<p>&lt;students&gt; 500 &lt;\/students&gt;<\/p>\n<p>&lt;\/department&gt;<\/p>\n<p>&lt;course course_code=\u201cCS8204\u201d dept_name=\u201cCSE\u201d course_incharge=\u201c54783\u201d&gt; &lt;title&gt; DBMS &lt;\/title&gt;<\/p>\n<p>&lt;credits&gt; 3 &lt;\/credits&gt;<\/p>\n<p>&lt;\/course&gt;<\/p>\n<p>\u2026.<\/p>\n<p>&lt;course_incharge staff_id=\u201c54783\u201d dept_name=\u201cCSE\u201d&gt; &lt;name&gt; Arvind &lt;\/name&gt;<\/p>\n<p>&lt;salary&gt; 75000 &lt;\/salary&gt;<\/p>\n<p>&lt;\/course_incharge&gt;<\/p>\n<p>\u2026.<\/p>\n<p>&lt;\/university&gt;<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XML Schema<\/strong><\/p>\n<div>\n<ul>\n<li style=\"text-align: justify\">\u00a0 XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0Typing of values<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0Eg. integer, string, etc<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0Also, constraints on min\/max values<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0User-defined, complex types<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0Many more features, including<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0uniqueness and foreign key constraints, inheritance<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0XML Schema is itself specified in XML syntax, unlike DTDs<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0More-standard representation, but verbose<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0XML Scheme is integrated with namespaces<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0BUT: XML Schema is significantly more complicated than DTDs.<\/li>\n<\/ul>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 Rationale for XML in Databases<\/strong><\/p>\n<div>\n<ul>\n<li style=\"text-align: justify\">\u00a0 There are a number of reasons to directly specify data in XML or other document formats such as JSON.<\/li>\n<li style=\"text-align: justify\">\u00a0 For XML in particular, they include:<\/li>\n<li style=\"text-align: justify\">\u00a0 An enterprise may have a lot of XML in an existing standard format.<\/li>\n<li style=\"text-align: justify\">\u00a0Data may need to be exposed or ingested as XML, so using another format such as relational forces double-modeling of the data.<\/li>\n<li style=\"text-align: justify\">\u00a0XML is very well suited to sparse data, deeply nested data and mixed content (such as text with embedded markup tags).<\/li>\n<li style=\"text-align: justify\">\u00a0XML is human readable whereas relational tables require expertise to access.<\/li>\n<li style=\"text-align: justify\">Metadata is often available as XML.<\/li>\n<li style=\"text-align: justify\">Semantic web data is available as RDF\/XML.<\/li>\n<\/ul>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 XML in Databases<\/strong><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p style=\"text-align: justify\">\u00a0 \u00a0 \u00a0 Steve O&#8217;Connell gives one reason for the use of XML in databases: the increasingly common use of XML for data transport hich has meant that &#8220;data is extracted from databases and put into XML documents and vice-versa\u201d.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In content-based applications, the ability of the native XML database also minimizes the need for extraction or entry of metadata to support searching and navigation.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0 Querying and Transforming XML Data<\/strong><\/p>\n<ul>\n<li>Translation of information from one XML schema to another<\/li>\n<li>Querying on XML data<\/li>\n<li>Above two are closely related, and handled by the same tools<\/li>\n<li>Standard XML querying\/translation languages<\/li>\n<li>XPath<\/li>\n<li>Simple language consisting of path expressions<\/li>\n<li>XSLT<\/li>\n<li>Simple language designed for translation from XML to XML and XML to HTML<\/li>\n<li>XQuery<\/li>\n<li>An XML query language with a rich set of features<\/li>\n<\/ul>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">Tree Model of XML Data<\/strong><\/p>\n<div>\n<ul>\n<li style=\"text-align: justify\">\u00a0Query and transformation languages are based on a <strong>tree model<\/strong> of XML data.<\/li>\n<li style=\"text-align: justify\">\u00a0An XML document is modeled as a tree, with <strong>nodes<\/strong> corresponding to elements and attributes.<\/li>\n<li style=\"text-align: justify\">\u00a0Element nodes have child nodes, which can be attributes or subelements.<\/li>\n<li style=\"text-align: justify\">\u00a0Text in an element is modeled as a text node child of the element<\/li>\n<li style=\"text-align: justify\">\u00a0Children of a node are ordered according to their order in the XML document.<\/li>\n<li style=\"text-align: justify\">\u00a0Element and attribute nodes (except for the root node) have a single parent, which is an element node.<\/li>\n<li style=\"text-align: justify\">\u00a0The root node has a single child, which is the root element of the document.<\/li>\n<\/ul>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0XPath\u00a0<\/strong><\/p>\n<ul>\n<li><span style=\"text-align: initial;font-size: 1em\">XPath is used to address (select) parts of documents using <\/span><strong style=\"text-align: initial;font-size: 1em\">path<\/strong> <strong style=\"text-align: initial;font-size: 1em\">expressions<\/strong><\/li>\n<li><span style=\"text-align: initial;font-size: 1em\">A path expression is a sequence of steps separated by \u201c\/\u201d<\/span><\/li>\n<li><span style=\"text-align: initial;font-size: 1em\">\u00a0Think of file names in a directory hierarchy<\/span><\/li>\n<li><span style=\"text-align: initial;font-size: 1em\">Result of path expression: set of values that along with their containing elements\/attributes match the specified path<\/span><\/li>\n<\/ul>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 E.g. \/university\/course_incharge\/name evaluated on the university data we saw earlier returns\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0&lt;name&gt;Arvind&lt;\/name&gt;<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0&lt;name&gt;Balu&lt;\/name&gt;<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0E.g.\/university\/course_incharge\/name\/text( )<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0returns the same names, but without the enclosing tags Arvind, Balu<\/span><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0XQuery<\/strong><\/p>\n<div>\n<ul>\n<li>XQuery is a general purpose query language for XML data<\/li>\n<li>XQuery is derived from the Quilt query language, which itself borrows from SQL, XQL and XML-QL<\/li>\n<li>XQuery uses a<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 \u00a0for \u2026 let \u2026 where \u2026 order by \u2026result <\/strong>\u2026<\/p>\n<p>syntax<\/p>\n<p><strong>for<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00f3 SQL <strong>from<\/strong><\/p>\n<p><strong>where <\/strong>\u00f3 SQL<strong> where<\/strong><\/p>\n<p><strong>order by <\/strong>\u00f3 SQL<strong> order by<\/strong><\/p>\n<p><strong>result <\/strong>\u00f3 SQL<strong> select<\/strong><\/p>\n<p><strong>let <\/strong>allows temporary variables, and has no equivalent in SQL<\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0<\/strong><\/p>\n<p><strong> \u00a0XSLT<\/strong><\/p>\n<ul>\n<li>\u00a0A <strong>stylesheet<\/strong> stores formatting options for a document, usually separately from document.<\/li>\n<li>\u00a0E.g. an HTML style sheet may specify font colors and sizes for headings, etc.<\/li>\n<li>\u00a0The <strong>XML Stylesheet Language (XSL)<\/strong> was originally designed for generating HTML from XML.<\/li>\n<li>\u00a0XSLT is a general-purpose transformation language.<\/li>\n<li>\u00a0Can translate XML to XML, and XML to HTML.<\/li>\n<li>\u00a0XSLT transformations are expressed using rules called <strong>templates.<\/strong><\/li>\n<li>\u00a0Templates combine selection using XPath with construction of results.<\/li>\n<\/ul>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Application Program Interface<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>There are two standard application program interfaces to XML data:<\/p>\n<p><strong>\u00a0 \u00a0 SAX <\/strong>(Simple API for XML)<\/p>\n<ul>\n<li style=\"text-align: justify\">\u00a0 \u00a0Based on parser model, user provides event handlers for parsing events<\/li>\n<li style=\"text-align: justify\">\u00a0 \u00a0E.g. start of element, end of element<\/li>\n<li style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0 DOM <\/strong><span style=\"text-align: initial;font-size: 1em\">(Document Object Model)<\/span><\/li>\n<li style=\"text-align: justify\">\u00a0\u00a0<strong style=\"text-align: initial;font-size: 1em\">XML <\/strong><span style=\"text-align: initial;font-size: 1em\">data is parsed into a tree representation<\/span><\/li>\n<li style=\"text-align: justify\">\u00a0Variety of functions provided for traversing the DOM tree<\/li>\n<li style=\"text-align: justify\">\u00a0E.g.: Java DOM API provides Node class with methods getParentNode( ), getFirstChild( ), getNextSibling( ) getElementsByTagName( ), \u2026<\/li>\n<li style=\"text-align: justify\">Also provides functions for updating DOM tree<\/li>\n<\/ul>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 Storage of XML Data<\/strong><\/p>\n<div>\n<ul>\n<li>\u00a0 \u00a0XML data can be stored in<\/li>\n<li>\u00a0 \u00a0Non-relational data stores<\/li>\n<li>\u00a0 \u00a0Flat files<\/li>\n<li>\u00a0 \u00a0Natural for storing XML<\/li>\n<li>\u00a0 \u00a0But has all problems discussed in Chapter 1 (no concurrency, no recovery, \u2026)<\/li>\n<li>\u00a0 \u00a0XML database<\/li>\n<li>\u00a0 \u00a0Database built specifically for storing XML data, supporting DOM model and declarative querying<\/li>\n<li>\u00a0 \u00a0Currently no commercial-grade systems<\/li>\n<li>\u00a0 \u00a0Relational databases<\/li>\n<li>\u00a0 \u00a0Data must be translated into relational form<\/li>\n<li>\u00a0 \u00a0Advantage: mature database systems<\/li>\n<li>\u00a0 \u00a0Disadvantages: overhead of translating data and queries<\/li>\n<\/ul>\n<\/div>\n<p><strong>\u00a0 \u00a0 Storage of XML in Relational Databases<\/strong><\/p>\n<ul>\n<li>Alternative Representations :<\/li>\n<li>String Representation<\/li>\n<li>Tree Representation<\/li>\n<li>Map to relations<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-190\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-86.png\" alt=\"\" width=\"657\" height=\"189\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-86.png 657w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-86-300x86.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-86-65x19.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-86-225x65.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-86-350x101.png 350w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0 String Representation<\/strong><\/p>\n<ul>\n<li>Store each top level element as a string field of a tuple in a relational database.<\/li>\n<li>Use a single relation to store all elements, or<\/li>\n<li>Use a separate relation for each top-level element type.<\/li>\n<li>E.g.\u00a0 account, customer, depositor relations.<\/li>\n<li>Each with a string-valued attribute to store the element.<\/li>\n<li>Indexing:<\/li>\n<li style=\"text-align: justify\">Store values of subelements\/attributes to be indexed as extra fields of the relation, and build indices on these fields.<\/li>\n<li>E.g. customer_name or account_number.<\/li>\n<li>Some database systems support <strong>function indices,<\/strong> which use the result of a function as the key value.<\/li>\n<li>The function should return the value of the required subelement\/attribute.<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 \u00a0 Benefits:<\/strong><\/p>\n<\/div>\n<div>\n<ul>\n<li style=\"text-align: justify\">\u00a0 Can store any XML data even without DTD<\/li>\n<li style=\"text-align: justify\">\u00a0 As long as there are many top-level elements in a document, strings are small compared to full document<\/li>\n<li style=\"text-align: justify\">\u00a0Allows fast access to individual elements.<\/li>\n<\/ul>\n<p><strong>\u00a0 Drawback:<\/strong><\/p>\n<ul>\n<li>\u00a0Need to parse strings to access values inside the elements<\/li>\n<li>\u00a0P<span style=\"font-size: 1em\">arsing is slow.<\/span><\/li>\n<li><strong>Tree representation: <\/strong>model XML data as tree and store using relations <em>nodes(id, parent_id, type, label, value)<\/em><\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-191 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-87.png\" alt=\"\" width=\"515\" height=\"169\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-87.png 515w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-87-300x98.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-87-65x21.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-87-225x74.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-87-350x115.png 350w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/p>\n<ul>\n<li>Each element\/attribute is given a unique identifier<\/li>\n<li>Type indicates element\/attribute<\/li>\n<li>Label specifies the tag name of the element\/name of attribute<\/li>\n<li>Value is the text value of the element\/attribute<\/li>\n<li>Can add an extra attribute <em>position<\/em> to record ordering of children<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 Benefit:<\/strong><\/p>\n<ul>\n<li>Can store any XML data, even without DTD.<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 \u00a0Drawbacks:<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify\">Data is broken up into too many pieces, increasing space overheads.<\/li>\n<li style=\"text-align: justify\">Even simple queries require a large number of joins, which can be slow.<\/li>\n<\/ul>\n<p style=\"text-align: justify\"><strong>\u00a0 \u00a0 \u00a0Mapping XML data to Relations<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify\">Relation created for each element type whose schema is known:<\/li>\n<li style=\"text-align: justify\">An id attribute to store a unique id for each element.<\/li>\n<li style=\"text-align: justify\">A relation attribute corresponding to each element attribute.<\/li>\n<li style=\"text-align: justify\">A parent_id attribute to keep track of parent element.<\/li>\n<li style=\"text-align: justify\">As in the tree representation.<\/li>\n<li style=\"text-align: justify\">Position information (ith child) can be store too.<\/li>\n<li style=\"text-align: justify\">All sub-elements that occur only once can become relation attributes.<\/li>\n<li style=\"text-align: justify\">For text-valued sub-elements, store the text as attribute value.<\/li>\n<li style=\"text-align: justify\">For complex sub-elements, can store the id of the sub-element.<\/li>\n<li style=\"text-align: justify\">Sub-elements that can occur multiple times represented in a separate table.<\/li>\n<li style=\"text-align: justify\">Similar to handling of multivalued attributes when converting ER diagrams to tables.<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 Storing XML Data in Relational Systems<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify\">Applying above ideas to department elements in university-1 schema, with nested course elements, we get\u00a0<em style=\"text-align: initial;font-size: 1em\">department<\/em><span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">id<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> dept_name<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> faculty<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> students<\/em><span style=\"text-align: initial;font-size: 1em\">)\u00a0<\/span><em style=\"text-align: initial;font-size: 1em\">course<\/em><span style=\"text-align: initial;font-size: 1em\">(<\/span><em style=\"text-align: initial;font-size: 1em\">parent id<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> course_code<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> dept_name<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> title<\/em><span style=\"text-align: initial;font-size: 1em\">,<\/span><em style=\"text-align: initial;font-size: 1em\"> credits<\/em><span style=\"text-align: initial;font-size: 1em\">)<\/span><\/li>\n<li style=\"text-align: justify\"><strong>Publishing<\/strong>: process of converting relational data to an XML format<\/li>\n<li style=\"text-align: justify\"><strong>Shredding<\/strong>: process of converting an XML document into a set of tuples to be inserted into one or more relations<\/li>\n<li style=\"text-align: justify\">XML-enabled database systems support automated publishing and shredding<\/li>\n<li style=\"text-align: justify\">Many systems offer <em>native storage<\/em> of XML data using the <strong>xml<\/strong> data type. Special internal data structures and indices are used for efficiency<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 \u00a0XML Enabled databases<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XML enabled databases typically offer one or more of the following approaches to storing XML within the traditional relational structure:<\/p>\n<ul>\n<li>XML is stored into a CLOB (Character Large OBject).<\/li>\n<li>XML is `shredded` into a series of Tables based on a Schema.<\/li>\n<li>XML is stored into a native XML Type as defined by ISO Standard 9075-14.<\/li>\n<\/ul>\n<p>RDBMS that support the ISO XML Type are:<\/p>\n<ul>\n<li>IBM DB2 (pureXML)<\/li>\n<li>Microsoft SQL Server.<\/li>\n<li>Oracle Database.<\/li>\n<li>PostgreSQL<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 XML Enabled databases<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">XML enabled databases typically offer one or more of the following approaches to storing XML within the traditional relational structure:<\/p>\n<ul>\n<li>XML is stored into a CLOB (Character Large OBject).<\/li>\n<li>XML is `shredded` into a series of Tables based on a Schema.<\/li>\n<li>XML is stored into a native XML Type as defined by ISO Standard 9075-14.<\/li>\n<\/ul>\n<p>RDBMS that support the ISO XML Type are:<\/p>\n<ul>\n<li>IBM DB2 (pureXML)<\/li>\n<li>Microsoft SQL Server.<\/li>\n<li>Oracle Database.<\/li>\n<li>PostgreSQL<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 \u00a0Key Features<\/strong><\/p>\n<ul>\n<li>Has an XML document as at least one fundamental unit of (logical) storage, just as a relational database has a Row in a table as a fundamental unit of (logical) storage.<\/li>\n<li>Need not have any particular underlying physical storage model.<\/li>\n<li>For example, NXDs can use optimized, proprietary storage formats.<\/li>\n<li>This is a key aspect of XML databases.<\/li>\n<li>Managing XML as large strings is inefficient due to the extra markup in XML.<\/li>\n<li>Compressing and indexing XML allows the illusion of directly accessing, querying and transforming XML while gaining the performance advantages of working with optimized binary tree structures.<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 \u00a0Language Features<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-192 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88.png\" alt=\"\" width=\"882\" height=\"343\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88.png 882w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88-300x117.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88-768x299.png 768w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88-65x25.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88-225x88.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-88-350x136.png 350w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Supported API<\/strong><\/p>\n<\/div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-193 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89.png\" alt=\"\" width=\"785\" height=\"267\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89.png 785w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89-300x102.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89-768x261.png 768w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89-65x22.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89-225x77.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-89-350x119.png 350w\" sizes=\"auto, (max-width: 785px) 100vw, 785px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>XML Database Applications<\/strong><\/p>\n<ul>\n<li>Storing and exchanging data with complex structures<\/li>\n<li>g. Open Document Format (ODF) format standard for storing Open Office and Office Open XML (OOXML) Format standard for storing Microsoft Office documents<\/li>\n<li>Numerous other standards for a variety of applications<\/li>\n<li>ChemML, MathML<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-194 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-90.png\" alt=\"\" width=\"476\" height=\"164\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-90.png 476w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-90-300x103.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-90-65x22.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-90-225x78.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-90-350x121.png 350w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 XML Database Applications<\/strong><\/p>\n<\/div>\n<p>Standard for data exchange for Web services<\/p>\n<ul>\n<li>remote method invocation over HTTP protocol Data mediation<\/li>\n<li>Common data representation format to bridge different systems<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-195 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-91.png\" alt=\"\" width=\"332\" height=\"200\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-91.png 332w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-91-300x181.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-91-65x39.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-91-225x136.png 225w\" sizes=\"auto, (max-width: 332px) 100vw, 332px\" \/><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0 Summary<\/strong><\/p>\n<\/div>\n<ul>\n<li>\u00a0Introduction to XML<\/li>\n<li>XML Syntax<\/li>\n<li>Querying and Transforming XML data<\/li>\n<li>Different representations of XML in relational data<\/li>\n<li>Storing XML data in Relational Systems<\/li>\n<li>XML Database Applications<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-196 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-92.png\" alt=\"\" width=\"631\" height=\"361\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-92.png 631w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-92-300x172.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-92-65x37.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-92-225x129.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-92-350x200.png 350w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><\/p>\n","protected":false},"author":4,"menu_order":23,"template":"","meta":{"_acf_changed":false,"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-r-baskaran"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-181","chapter","type-chapter","status-publish","hentry","contributor-dr-r-baskaran"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":7,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/181\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/181\/revisions\/384"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/181\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapter-type?post=181"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/contributor?post=181"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/license?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}