Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Data Management XML Data Model 1. Semi-structured Data Model A data model, based on graphs, for representing both regular and irregular data. Basic.

Similar presentations


Presentation on theme: "Web Data Management XML Data Model 1. Semi-structured Data Model A data model, based on graphs, for representing both regular and irregular data. Basic."— Presentation transcript:

1 Web Data Management XML Data Model 1

2 Semi-structured Data Model A data model, based on graphs, for representing both regular and irregular data. Basic ideas Self-describing data. The content comes with its own description; – contrast with the relational model, where schema and content are represented separately. Flexible typing. Data may be typed (i.e., “such nodes are integer values” or “this part of the graph complies to this description”); often no typing, or a very flexible one Serialized form. The graph representation is associated to a serialized form, convenient for exchanges in an heterogeneous environment. 2

3 Self-describing data Starting point: association lists, i.e., records of label-value pairs. Natural extension: values may themselves be other structures: Further extension: allow duplicate labels. {name: "Alan", tel: , {name: {first: "Alan", last: "Black"}, tel: , {name: “Alan’’, tel: , tel: } 3

4 Tree-based representation Data can be graphically represented as trees: label structure can be captured by tree edges, and values reside at leaves. 4

5 Tree-based representation: labels as nodes Another choice is to represent both labels and values as vertices. The XML data model adopts this latter representation. 5

6 Representation of regular data The syntax makes it easy to describe sets of tuples as in: – relational data can be represented – for regular data, the semi-structure representation is highly redundant. { person: {name: "alan", phone: , person: {name: "sara", phone: , person: {name: "fred", phone: , } 6

7 Representation of irregular data Many possible variations in the structure: missing values, duplicates, changes, etc. – Nodes can be identified, and referred to by their identity. Cycles and objects models can be described as well. { person: {name: "alan", phone: , person: &314 { name: {first: "Sara", last: "Green" }, phone: , spouse: &443 }, person: &443 { name: "fred", Phone: , Height: 183, spouse: &314 }} 7

8 XML represents Semistructured Data Do not care about the type of the data Serialize the data by annotating each data item explicitly with its description (e.g. name, phone, etc.) Such data is called self-describing Serialization: convert data into a byte stream that can be easily transmitted and reconstructed at the receiver Self-describing data wastes space but provides interoperability (required on the web) Semistructured data models – XML, JSON (Javascript Object Notation) 8

9 XML as a Semi-structured Data Explained Missing attributes: – John 1234 – Joe no phone ! Repeated attributes – Mary

10 XML as a Semistructured Data Explained Attributes with different types in different objects – John Smith complex name ! 1234 Nested collections (no 1NF) Heterogeneous collections: – contains both s and s 10

11 XML in brief XML is the World-Wide-Web Consortium (W3C) standard for Web data exchange. – XML documents can be serialized in a normalized encoding (typically iso , or utf-8), and safely transmitted on the Internet. – XML is a generic format, which can be specialized in “dialects” for specific domain (e.g., XHTML) – The W3C promotes companion standards: DOM (object model), XSchema (typing), XPath (path expression), XSLT (restructuring), Xquery (query language), and many others. XML is a simplified version of SGML, a long-term used language for technical documents. 11

12 XML documents An XML document is a labeled, unranked, ordered tree: – Labeled means that some annotation, the label, is attached to each node. – Unranked means that there is no a priori bound on the number of children of a node. – Ordered means that there is an order between the children of each node. XML specifies nothing more than a syntax: no meaning is attached to the labels. A dialect, on the other hand, associates a meaning to labels (e.g., title in XHTML). 12

13 XML documents are trees John 3634 Sue 6343 Dick row name phone “John”3634“Sue”“Dick” person XML: person Serialized representation

14 XML and Semistructured Data: Similarities and Differences Alan 42 Alan 42 { person: &o123 { name: “Alan”, age: 42, } } { person: &o123 { name: “Alan”, age: 42, } } 14 person nameage person name age father … { person: { father: &o123 …} } similar on trees, different on graphs

15 XML describes structured content Applications cannot interpret unstructured content: XML provides a means to structure this content: Now, an application can access the XML tree, extract some parts, rename the labels, reorganize the content into another structure, etc. 15 The book ‘‘Fundations of Databases’’, written by Serge Abiteboul, Rick Hull and Victor Vianu, published in 1995 by Addison-Wesley Foundations of Databases Abiteboul Hull Vianu Addison Wesley

16 Applications associate semantics to XML docs Letter document

17 Applications associate semantics to XML docs Letter style sheet Some software then produces the actual letter to mail or if letter then... if header then... if author then... if date then... if recipient then... if cc then... if body then... if text then... if signature then...

18 Serialized and tree-based forms The serialized form is a textual, linear representation of the tree; it complies to a (sometimes complicated) syntax; Tree-based forms implement in a specific context, object-oriented model, the abstract tree representation (Document Object Model) Typically, an application gets a document in serialized form, parse it in tree form, and serializes it back at the end. 18

19 Serialized and tree-based forms: text and elements The basic components of an XML document are element and text. Here is an element, whose content is a text. The tree form of the document, modeled in DOM: each node has a type, either Document or Text. 19 Textual content

20 Serialized and tree-based forms: nesting elements Serialized form: The content of an element is the part between the opening and ending tags Tree-based form: the subtree rooted at the corresponding Element node (in DOM) 20 Textual content Another content

21 Serialized and tree-based forms: attributes Serialized form: Attributes are pairs of name/value attached to an element The content of an attribute is always atomic text (no nesting) Attributes are not ordered, and there cannot be two attributes with the same name in an element Tree-based form: Attributes are special child nodes of the Element node (in DOM) 21 Textual content

22 Serialized and tree-based forms: the document root A document with its prologue, and element root In the DOM representation, the prologue appears as a Document node, called the root node. 22 Document content must always be enclosed in a single opening/ending tag, called the element root The first line of the serialized form must always be the prologue if there is one: Document content.

23 Web Data Management with XML Publishing – an XML document can easily be converted to another XML document (same content, but another structure) – Web publishing is the process of transforming XML documents to XHTML. Integration – XML documents from many sources can be transformed in a common dialect, and constitute a collection. – Search engines, or portals, provide browsing and searching services on collections of XML documents. Distributed Data Processing – many softwares can be adapted to consume/produce XML- represented data. – Web services provide remote services for XML data processing. 23

24 Web Publishing: restructuring to XHTML The Web application produces some XML content, structured in some application-dependent dialect, on the server. In a second phase, the XML content is transformed in an XHTML document that can be visualized by humans. The transformation is typically expressed in XSLT, and can be processed either on the server or on the client. 24

25 Web publishing: content + presentation instructions XML content Document in XHTML 25 Foundations of Databases Abiteboul Hull Vianu Addison Wesley Bibliography Foundations of Databases Abiteboul, Hull, Vianu Addison Wesley, 1995 Data on the Web Abiteoul, Buneman, Suciu Morgan Kaufmann, 1999

26 Web publishing The same content may be published using different means: – Web publishing: XML  XHTML – WAP (Wireless Application Protocol): XML  WML 26

27 Web publishing Data obtained from a relational database and from XML files XSLT restructures the XML data Produces XHTML pages for a browser 27

28 Web Integration: gluing together heterogeneous sources The portal receives (possibly continuously) XML- structured content, each source using its own dialect. Each feed provides some content, extracted with XSLT or XQuery, or any convenient XML processing tool (e.g., SAX). 28

29 Data integration 29

30 Distributed Data Management with XML XML encoding is used to exchange information between applications. A specific dialect, WDSL, is used to describe Web Services Interfaces. 30

31 Exploiting XML documents 31

32 XML dialects Dialects define specialized structures, constraints and vocabularies to construct ad hoc XML contents that can be used and exchanged in a specific application area RSS is an XML dialect for describing content updates that is heavily used for blog entries, news headlines or podcasts. WML (Wireless Mark-up Language) is used in Web sites by wireless applications based on the Wireless Application Protocol (WAP). MathML (Mathematical Mark-up Language) is an XML dialect for describing mathematical notation and capturing both its structure and content. 32

33 XML dialects Xlink (XML Linking Language) is an XML dialect for defining hyperlinks between XML documents. These links are expressed in XML and may be introduced inside XML documents. SVG (Scalable Vector Graphics) is an XML dialect for describing two-dimensional vector graphics, both static and animated. With SVG, images may contain outbound hyperlinks in XLinks. 33

34 XML dialects – SVG example 34 Some SVG text Some SVG text

35 XML standards SAX (Simple API for XML) sees an XML document as a sequence of tokens (its serialization). DOM (Document Object Model) is an object model for representing (HTML and) XML document independently of the programming language. XPath (XML Path Language) that we will study, is a language for addressing portions of an XML document. 35

36 XML standards XQuery (that we will study) is a flexible query language for extracting information from collections of XML documents. XSLT (Extensible Stylesheet Language Transformations), that we will study, is a language for specifying the transformation of XML documents into other XML documents. Web services provide interoperability between machines based on Web protocols. 36

37 Processing an XML Document with SAX and DOM A SAX parser transforms an XML document into a flow of events. – Examples of events: start/end of a document, the start/end of an element, a text token, a comment, etc. Example: Load data in XML format into a relational database when document start is received, connect to the database; 2. when a Movie open tag is received, create a new Movie record; (a) when a text node is received, assign its content to X; (b) when a Title close tag is received, assign X to Movie.Title; (c) when a Year close tag is received, assign X to Movie.Year, etc. 3. when a Movie close tag is received, insert the Movie record in the database (and commit the transaction); 4. when document end is received, close the database connection.

38 Sax SAX is a good choice when the content of a document needs to be examined once SAX handler written in Java – It features methods that handle SAX events: opening and closing tags; character data – See next slide 38

39 39 import org.xml.sax.*; import org.xml.sax.helpers.LocatorImpl; public class SaxHandler implements ContentHandler { /** Constructor */ public SaxHandler() { super(); } /** Handler for the beginning and end of the document */ public void startDocument() throws SAXException { out.println("Start the parsing of document"); } public void endDocument() throws SAXException { out.println("End the parsing of document"); } /** Opening tag handler */ public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributes) throws SAXException { out.println("Opening tag: " + localName); // Show the attributes, if any if (attributes.getLength() > 0) { System.out.println(" Attributes: "); for (int index = 0; index < attributes.getLength(); index++) { out.println(" - " + attributes.getLocalName(index) + " = " + attributes.getValue(index)); } } } /** Closing tag handler */ public void endElement(String nameSpaceURI, String localName, String rawName) throws SAXException { out.print("Closing tag : " + localName); out.println(); } /** Character data handling */ public void characters(char[] ch, int start, int end) throws SAXException { out.println("#PCDATA: " + new String(ch, start, end)); }}

40 DOM (Document Object Model) A DOM parser transforms an XML document into a tree and offers an object API for that tree. A partial view of the Class hierarchy of DOM 40

41 Parsing XML Documents  A parser checks XML documents for well- formedness or validates it against a schema  So, what is parsing ? well, in computer terminology.. ‘ to analyze or separate (input, for example) into more easily processed components’  XML parsers load XML documents and provide access to it’s contents in the form of objects

42 Parsing XML Documents  A Validating Parser: can use a DTD or schema to verify that a document is properly constructed  A Non-Validating Parser: only requires the document to be well formed; many free parsers on the Web are non-validating  Stream-Based Parsers: read through the document and signal the application every time a new component appears  Tree-Based Parsers: read the entire document and give the application a tree structure corresponding to the element structure of the document

43 Parsing XML Documents  DOM API: language & platform independent interfaces for accessing & manipulating info. in XML documents  Document checked to see if it’s well formed and valid  Parser then converts information into a tree of nodes  A tree starts at one root node; in DOM terms, called a document object instance  You can modify, delete and create leaves and branches on the tree using interfaces in API

44 Parsing XML Documents  Titles.xml; a sample XML document BU1111 Cooking with Computers: Surreptitious Balance Sheets business Helpful hints on how to use your electronic T05:00:00 BU7832 Straight Talk About Computers business Annotated analysis of what computers can do for you T05:00:00

45 Parsing XML Documents

46 DOM  DOM provides interfaces in it’s hierarchy of Node objects  Node: an XML Document object created after a DOM parser reads an XML file  Inheritance relationship between important interfaces

47 DOM A sample document object tree

48 Methods of Node Object MethodDescription hasChildNodes() finds out if a Node has children, takes no parameters, returns a Boolean getNodeType() returns the type of a particular Node. The type is a constant integer used to identify different types of Node s appendChild() adds a new child object, which is passed to the method, to the current Node cloneNode() returns a duplicate of the Node hasAttributes() returns a Boolean true if the Node has any attributes. This method was added in DOM Level 2 insertBefore() takes a new child Node and a reference child Node and inserts the new child Node before the reference Node isSupported() tests whether or not this implementation of the DOM supports a specific feature. This method was added in DOM Level 2 and takes a version number and a feature as parameters normalize() puts all text nodes in the full depth of the sub-tree underneath this Node removeChild() removes the specified child replaceChild() replaces the specified child with the new child passed

49 Methods of Node Object MethodDescription getAttribute() retrieves the specified attribute. getAttributeNS() retrieves the specified attribute by local name and namespace. This method was added in Level 2. getAttributeNode() retrieves an Attr node by name. getAttributeNodeNS() retrieves an Attr node by local name and namespace. This method was added in Level 2. getElementsByTagName() returns a NodeList of all child elements of a given tag name in the order in which they are encountered. getElementsByTagNameNS() returns a NodeList of all child elements of a given tag by local name and namespace in the order in which they are encountered. This method was added in Level 2. hasAttribute() returns a Boolean true if the specified attribute is present. Returns Boolean false otherwise. hasAttributeNS() returns a Boolean true if the specified attribute, by local name and namespace, is present. Returns Boolean false otherwise. This method was added in Level 2. removeAttribute() removes the specified attribute. removeAttributeNS() removes the attribute specified by local name and namespace. This method was added in Level 2.

50 Methods of Node Object MethodDescription removeAttributeNode() removes the specified Attr node. setAttribute() adds a new attribute. If an attribute of the same name exists, its value is changed to the specified value. setAttributeNS() adds a new attribute. If an attribute of the same local name and namespace exists, its value is changed to the specified value. This method was added in Level 2. setAttributeNode() adds a new Attr node. If an Attr node of the same name exists, its value is changed to the specified value. setAttributeNodeNS() adds a new Attr node. If an Attr node of the same local name and namespace exists, its value is changed to the specified value. This method was added in Level 2.

51 DOM  Node Interface: NodeList is an iterator for a Nodes list A DOM NodeList object  NodeList has only a single method, item() ; it returns the Node at the indexed position passed to the method

52 SAX  SAX Parser: stream in documents according to specific events  SAX parser doesn't have a default object model  SAX parser read in a XML document and start events based on the following:  open or start of elements  closing or end of documents  #PCDATA and CDATA sections  processing instructions, comments & entity declarations  3 steps to using SAX in your applications:  creating a custom object model, like a Book class  creating a SAX parser  creating a document handler to turn your document into instances of your custom object model

53 SAX  Document Handler: is a listener for the various events fired by the SAX parser  Events are fired based on all registered document event listeners and translated into method calls A SAX event order  SAX parser exposes the document as a series of events that are translated into method calls

54 DOM Vs SAX  The following are DOM benefits you should focus on:  it allows random access to the document  complex searches can be easily implemented  the DTD or schema is available  the DOM is read/write  The following list contains some of the most useful benefits of SAX :  it can parse files of any size  it is a fast processing method  you can build your own data structure  you can access only a small subset of info. if desired

55 Example Parsers  MSXML: first parser which can perform both SAX and DOM-based parsing, from Microsoft  Xerces: available in three languages, from the Apache Group at  IBM's XML for Java : formula/xml formula/xml  Microstar's Ifred:  Sun's Java API for XML:  Oracle's XML Parser for Java:

56 XPath Language for expressing paths in an XML document – Navigation: child, descendant, parent, ancestor – Tests on the nature of the node – More complex selection predicates Means to specify portions of a document Basic tool for other XML languages: Xlink, XSLT, Xquery 56

57 XQuery Query language: “SQL for XML” Like SQL: select portions of the data and reconstruct a result Query structure: FLW (pronounced "flower") $p : scans the sequence of publishers $b : scans the sequence of books for a publisher WHERE filters out some publishers RETURN constructs the result 57 FOR $p IN document("bib.xml")//publisher LET $b := document("bib.xml)//book[publisher = $p] WHERE count($b) > 100 RETURN $p

58 XSLT Transformation language: “Perl for XML” An XSLT style sheet includes a set of transformation rules: pattern/template Pattern: based on XPATH expressions; it specifies a structural context in the tree Template: specifies what should be produced Principle: when a pattern is matched in the source document, the corresponding templates produces some data 58

59 XLINK XML Linking Language Advanced hypertext primitives Allows inserting in XML documents descriptions of links to external Web resources Simple mono-directional links ala (HREF) HTML Multidirectional links XLink relies on XPath for addressing portions of XML documents 59

60 XLink Generalizes HTML’s href XLink links resources, which include documents, audio, video, database data, etc. Many types: simple, extended, locator, arc, resource, or title 60 ..... ..... required attributes optional attributes

61 XLink The linking element (i.e., person) that references document2 is called a local resource. The resource referenced is called the remote resource. Traversal Path between the local and remote resources is to get from resource A to resource B by following the defined link. Arc: how to traverse a pair of resources, including the direction of traversal and possibly application behavior information as well. Outbound arc: An arc that has a local starting resource and a remote ending resource Inbound arc: If an arc's ending resource is local but its starting resource is remote Third party arc: If neither the starting resource nor the ending resource is local 61

62 XLink show attribute specifies how to display a resource when it is loaded and can be – “new”, to display in new window – ”replace”, to replace current resource with the linked resource – ”embed”, replace current element with the linked resource – ”other”, XLink-aware application can decide how to display actuate attribute specifies when the resource should be retrieved and can be – “onLoad”, retrieve as soon as it is loaded – ”onRequest”, retrieve resource by clicking on the link – ”other”, XLink-aware applications can decide when to load – ”none”, no information when to load the resource 62

63 XLink The use of XLink elements and attributes requires declaration of the XLink namespace,

64 XLink Extended Links – for linking multiple combinations of local and remote resources. – The figure shows two unidirectional links – With XLink, we can create multidirectional links for traversing between resources 64

65 XLink Multidirectional links are not limited to just two resources, but can link any number of resources The links need not be traversed sequentially. 65

66 66 Books – root element A link to the book's authors with information located at /authors/deitel.xml A label's value is used to link one resource to another type locator, which specifies a remote resource When either Deitel, Harvey or Deitel, Paul is selected, the document deitel.xml will be retrieved Deitel, Harvey 17 Deitel, Paul

67 Java How to Program: Third edition Book - a local resource can be linked to (or from) an author or publisher create an outbound arc between the book local resource and the author remote resource arcrole provides information about the book's author an inbound arc, that has a starting resource that is remote, i.e., warehouseXYZ and an ending resource that is local,i.e. JavaBook create an outbound arc between the book local resource and the publisher remote resource

68 XLink a third-party arc, that has starting and ending resources that are both remote - Attribute show has value embed, which indicates that the ending resource should replace the starting resource when the link is traversed - Attribute actuate has value onLoad, so upon loading the XML document, the link is traversed - Because we consider the relationship between the publisher and warehouse as being different than the previous three arcs, we provide a different arcrole value for this link

69 XPointer An extension of XPath Usage: – href=www.a.b.c/document.xml#xpointerExprwww.a.b.c/document.xml#xpointerExpr XPointer can link to – specific locations (i.e., nodes in an XPath tree), or even – ranges of locations, in an XML document. XPointer also adds the ability to search XML documents by using string matching. 69

70 XPointer Pointing to a point (=XML element or character) Full XPointer form The name xpointer —called a scheme Deitel, Harvey 7 Deitel, Paul 8 Nieto, Tem 9 xlink:href = = 'author02'])"

71 XPointer If a document's unique identifier is referenced in an expression such as bare-name XPointer address – simplified expression Child sequence: e.g. #xpointer( /1/3/2/5), #xpointer( /bib/book[3]) Pointing to a range: e.g. #xpointer(id(3652 to 44)) Most interesting examples use XPath 71 xlink:href = "/contacts.xml#xpointer(id('author01‘))" xlink:href = "/contacts.xml#author01"


Download ppt "Web Data Management XML Data Model 1. Semi-structured Data Model A data model, based on graphs, for representing both regular and irregular data. Basic."

Similar presentations


Ads by Google