Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 6331 © Leonidas Fegaras XML1 Introduction to XML Leonidas Fegaras.

Similar presentations


Presentation on theme: "CSE 6331 © Leonidas Fegaras XML1 Introduction to XML Leonidas Fegaras."— Presentation transcript:

1 CSE 6331 © Leonidas Fegaras XML1 Introduction to XML Leonidas Fegaras

2 CSE 6331 © Leonidas Fegaras XML2 Traditional DB Applications Typically business oriented Large amount of data Data is well-structured, normalized, with predefined schema Large number of concurrent users (transactions) Simple data, simple queries, and simple updates Typically update intensive Small transactions High performance, high availability, scalability Data integrity and security are of major importance Good administrative support, nice GUIs

3 CSE 6331 © Leonidas Fegaras XML3 Document Applications Human friendly: what-you-see-is-what-you-get paradigm Focus on presentation Information is divided into multiple small documents Mostly static Implicit structure: section, subsection, paragraph, etc Meta-data: title, author, date, indexing keywords, etc Content structure: form/layout, inter-relationships, references Tagging: eg, for new paragraph Operations: retrieving, editing, spell-checking, printing, etc Information retrieval: keyword queries –most successful in web search engines (eg, Google)

4 CSE 6331 © Leonidas Fegaras XML4 Internet Applications Internet applications use heterogeneous, complex, hierarchical, fast-evolving, unstructured/semistructured data access mostly read-only data need 100% availability manage millions of users world-wide have high-performance requirements are concerned with security (encryption) like to customize data in a personalized manner expect to gain user’s trust for business-to-consumer transactions. Internet users choose speed and availability over correctness

5 CSE 6331 © Leonidas Fegaras XML5 Electronic Commerce Currently, mostly business-to-business (B2B) rather than business-to-consumer (B2C) interactions Focus on selling and buying: –Order management –Product catalogs –Product configuration Sales and marketing Education and training Web services Communities

6 CSE 6331 © Leonidas Fegaras XML6 Other Web Applications Web services –Many standards: SOAP, WSDL, UDDI Web integration –Heterogeneous data sources and types –Thousands of web-accessible data sources –Dynamic data –Data warehouses Web publishing –Access different types of content from browsers (PDF, HTML, XML) –Structured, dynamic, customized/personalized content –Integration with application –Accessible via major gateways and search engines Application integration –Transformation between different data formats (eg, XML, HTML) –Integration of multiple applications

7 CSE 6331 © Leonidas Fegaras XML7 Current Internet Application Architectures Architecture: Server-Tier: relational databases and gateways to diverse data sources, such as, files, OLE/DB etc. Use of enterprise servers Middle-Tier: provides data integration & distribution, query, etc. Consists of a web server and an application server Client-Tier: mostly a web browser, may use CGI scripts or Java Characteristics: Customization is achieved at the server site (customer data in a database) with some data at the client site (cookies) Load balancing is typically hardware based (multiple servers, DNS routers)

8 CSE 6331 © Leonidas Fegaras XML8 HTML My Web Page Introduction Look at this document It is very simple: human readable, can be edited by any editor It reflects document presentation, not the semantics or structure of data Universal: portable to any platform HTML pages are connected through hypertext links HTML pages can be located using web search engines attribute nameattribute value opening tag closing tag hypertext link

9 CSE 6331 © Leonidas Fegaras XML9 XML XML (eXtensible Markup Language) is a textual language for representing and exchanging data on the web It is designed to improve the functionality of the Web by providing more flexible and adaptable information identification Based on SGML It was developed around 1996 It is called extensible because –it is not a fixed format like HTML (a single, predefined markup language) –it is actually a metalanguage (a language for describing other languages) which lets you design your own customized markup languages for limitless different types of documents

10 CSE 6331 © Leonidas Fegaras XML10 XML (cont.) XML can be untyped (semistructured), but there are standards now for schema conformance –DTD –XML Schema Without schema, an XML document is well-formed if it satisfies simple syntactic constraints: –proper nesting of start and end tags With a schema, an XML document is valid if its structure conforms to a DTD or an XML Schema

11 CSE 6331 © Leonidas Fegaras XML11 Example Leonidas Fegaras (817) 272-3629 fegaras@cse.uta.edu Ramez Elmasri (817) 272-2348 elmasri@cse.uta.edu

12 CSE 6331 © Leonidas Fegaras XML12 Why XML is so Popular? It looks like HTML –simple, human-readable, easy to learn, universal Flexible & extensible, since you can represent any kind of data –unlike HTML HTML describes the presentation while XML describes the content Precise –well-formed: properly nested XML tags –valid: its structure may conform to a DTD or an XML Schema Supported by the W3C –trusted and adopted by industry Many standards around XML: schemas, query languages, etc

13 CSE 6331 © Leonidas Fegaras XML13 What XML has to do with Databases? XML is an important standardization for data representation and exchange, but still needs –to store and query large repositories of XML documents –data models and schema representations –query languages, data indexing, query optimizers –updates, view maintenance –concurrency, distribution, security, etc Example application: –an XML data repository distributed in a peer-to-peer network –answer queries, such as: find all books whose author is Smith and whose title contains the word “Web” –much like a web search engine, but for XML,... and for more precise querying

14 CSE 6331 © Leonidas Fegaras XML14 XML Syntax XML consists of tags and text XML documents conform to the following grammar: XMLdocument ::= Pi* Element Pi* Element ::= Stag (char | Pi | Element)* Etag Stag ::= ' ' Etag ::= ' ' Pi ::= ' ' Attributes ::= ( Name '=' String )* String ::= '"' char* '"' Tags come in pairs 8/25/2004 and must be properly nested:...... --- valid nesting...... --- invalid nesting Text is bounded by tags. PCDATA: parsed character data. eg, The Big Sleep 1935

15 CSE 6331 © Leonidas Fegaras XML15 XML Elements An element is a segment of an XML document between an opening and the matching closing tags Ramez Elmasri (817) 272-2348 elmasri@cse.uta.edu An element may contain a mixture of sub-elements and PCDATA An element is a segment An abbreviation: for an element with empty content, we can use: instead of:

16 CSE 6331 © Leonidas Fegaras XML16 Representing Data Using XML ● Nesting tags can be used to express various structures, such as a record: Ramez Elmasri (817) 272-2348 elmasri@cse.uta.edu We can represent a list by using the same tag repeatedly:...

17 CSE 6331 © Leonidas Fegaras XML17 XML structure XML: Ramez Elmasri (817) 272-2348 elmasri@cse.uta.edu is Lisp-like: (person (name “ Ramez Elmasri ”) (tel “ (817) 272-2348 ”) (email “ elmasri@cse.uta.edu ”)) and tree-like: person nametelemail Ramez Elmasri (817) 272-2348elmasri@cse.uta.edu

18 CSE 6331 © Leonidas Fegaras XML18 Attributes An opening tag may contain attributes –typically used to describe the content of an element Ramez Elmasri elmasri@cse.uta.edu It's not always clear when to use attributes 2787901 Ramez Elmasri elmasri@cse.uta.edu ID attributes are special: must be unique within the document An IDref attribute must refer to an existing ID in the same doc

19 CSE 6331 © Leonidas Fegaras XML19 Referencing Elements Using IDs/IDrefs Jane Doe John Doe Mary Doe Jack Doe

20 CSE 6331 © Leonidas Fegaras XML20 A Complete Example Amazon webmaster@amazon.com 1-800-555-9999 Unix Network Programming Addison Wesley 1995 Richard Stevens 38.68 An Introduction to Object-Oriented Design Addison Wesley 1996 Jo Levin Harold Perry 11.55

21 CSE 6331 © Leonidas Fegaras XML21 OODB Schema class Movie ( extent Movies, key title ) { attribute string title; attribute string director; relationship set casts inverse Actor::acted_In; attribute int budget; } ; class Actor ( extent Actors, key name ) { attribute string name; relationship set acted_In inverse Movie::casts; attribute int age; attribute set directed; } ;

22 CSE 6331 © Leonidas Fegaras XML22 In XML … Waking Ned Divine Kirk Jones III 100,000 Dragonheart Rob Cohen 110,000 Moondance Dagmar Hirtz 90,000 David Kelly 55 Sean Connery 68 Ian Bannen 45 :

23 CSE 6331 © Leonidas Fegaras XML23 DTD: Document Type Descriptor A DTD imposes a structure on an XML document Not quite a typing system –it is purely syntactic –now replaced by XML Schema Uses regular expressions to specify structure –firstnamean element with tag name firstname –book*zero or more books –year?an optional year –firstname,lastnamea firstname followed by lastname –book | journaleither a book or a journal

24 CSE 6331 © Leonidas Fegaras XML24 Example of XML Data Amazon webmaster@amazon.com 1-800-555-9999 Unix Network Programming Addison Wesley 1995 Richard Stevens 38.68...

25 CSE 6331 © Leonidas Fegaras XML25 DTD Example

26 CSE 6331 © Leonidas Fegaras XML26 Summary of the DTD Syntax A tagged element in a DTD is defined by where e is a DTD expression If e, e1, e2 are DTD expressions, then so are: –EMPTYempty content –#PCDATAany text –Aan element with tag name A –e1,e2e1 followed by e2 –e1 | e2either e1 or e2 –e*zero or more occurrences of e –e+one or more occurrences of e –e?optional e (zero or one occurrences) –(e) Note: tagged elements are global –must be defined once in a DTD

27 CSE 6331 © Leonidas Fegaras XML27 DTD Syntax (cont.) Attribute specification: type is: IDmust be unique within the document IDREFa reference to an existing ID IDREFSmultiple IDREFs CDATAany string accuracy is #REQUIRED, #IMPLIED, #FIXED 'value', value 'v1... vn' ID, IDref, and IDrefs attributes are not typed! Example: <!ATTLIST person id ID #REQUIRED children IDrefs #IMPLIED > the id attribute is required while the children attribute is optional

28 CSE 6331 © Leonidas Fegaras XML28 Connecting an XML document to a DTD In-line the DTD into the XML file: <!DOCTYPE db [... ]>... Better: put the DTD in a separate file and reference it by URL: Documents are validated against their DTD before they are used XML data DTD

29 CSE 6331 © Leonidas Fegaras XML29 Recursive DTDs We want to capture a person with a mother and a father First attempt: where the first person is the mother while the second is the father Second attempt: Third attempt: <!ATTLIST person id ID #REQUIRED mother IDREF #IMPLIED father IDREF #IMPLIED>

30 CSE 6331 © Leonidas Fegaras XML30 Back to the OODB Schema class Movie ( extent Movies, key title ) { attribute string title; attribute string director; relationship set casts inverse Actor::acted_In; attribute int budget; } ; class Actor ( extent Actors, key name ) { attribute string name; relationship set acted_In inverse Movie::casts; attribute int age; attribute set directed; } ;

31 CSE 6331 © Leonidas Fegaras XML31 DTD <!ATTLIST movie id ID #REQUIRED casts IDREFS #REQUIRED> <!ATTLIST actor id ID #REQUIRED acted_in IDREFS #REQUIRED>

32 CSE 6331 © Leonidas Fegaras XML32 XML Namespaces When merging multiple docs together, name collisions may occur A namespace is a mechanism for uniquely naming tagnames and attribute names to avoid name conflicts Tag/attribute names are now qualified names (QNames) (namespace ':')? localname example: bib:author A document may use multiple namespaces A DTD has its own namespace in which all names are unique A namespace in an XML doc is defined as an attribute: xmlns:bib=“http://lambda.uta.edu/biblio.dtd” where bib is the namespace name and the URL is the location of the DTD The default namespace is defined as xmlns=“URL” If not defined, it is the global namespace

33 CSE 6331 © Leonidas Fegaras XML33 Example <item xmlns=“http://www.acme.com/jp#supplies” xmlns:toy= “http://www.acme.com/jp#toys”> backpack cyberpet

34 CSE 6331 © Leonidas Fegaras XML34 Query Languages for XML Need a language for XML data for –extracting fragments (querying) –restructuring (data transformation) –integrating (eg, combining multiple XML documents) –browsing –presentation (eg, from XML to HTML) We will first learn XPath –used in extracting fragments from a single document –many XML query languages are based on XPath We will briefly discuss XSLT –for extracting, restructuring, and presentation over a single document We will focus later on XQuery –a full-fledged query language –much like OQL

35 CSE 6331 © Leonidas Fegaras XML35 XPath Describes a single navigation path in an XML document Selects a sequence of nodes reachable by the path –the order of nodes is the document order (which is the preorder of the XML tree: every node occurs before its children) Main construct: axis navigation Consists of one or more navigation steps separated by / A navigation step is a triplet axis :: node-test predicate* Each navigation path is evaluated relative to a context node Examples: –child::bib /descendant::author –descendant::book [ child::author/child::name = “Smith” ] /child::title Most people use shorthands –bib//author –//book[author/name=“Smith”]/title

36 CSE 6331 © Leonidas Fegaras XML36 Axis Forward Axis –child –descendant –attribute –self –descendant-or-self –following-sibling –following Reverse Axis –parent –ancestor –preceding-sibling –preceding –ancestor-or-self

37 CSE 6331 © Leonidas Fegaras XML37 Node Test personany element node whose name is person *any element node regardless of its name @priceany attribute whose name is price @*any attribute, regardless of its name node()any node text()any text node element()any element node element(person)any element node whose name is person element(person, surgeon)any element node whose name is person, and whose type annotation is surgeon element(*, surgeon)any element node whose type annotation is surgeon, regardless of its name attribute()any attribute node attribute(price)any attribute whose name is price attribute(*, xs:decimal)any attribute whose type annotation is xs:decimal, regardless of its name.

38 CSE 6331 © Leonidas Fegaras XML38 Abbreviated Syntax The attribute axis child:: can be omitted –section/para is an abbreviation for child::section/child::para, –section/@id is an abbreviation for child::section/attribute::id … unless the axis step contains an attribute test, … then the default axis is attribute –section/attribute(id) is short for child::section/attribute::attribute(id) The attribute axis attribute:: can be abbreviated by @ –para[@type="warning"] is short for child::para[attribute::type="warning"] // is replaced by /descendant-or-self::node()/ –div//para is short for child::div/descendant-or-self::node()/child::para.. is short for parent::node() –../title is short for parent::node()/child::title

39 CSE 6331 © Leonidas Fegaras XML39 Most Common Steps XPath stepnew context nodes /author all the children of a context node with tagname author /* all the children of the context node //book the context node and all its descendants with tagname book //* the context node and all its descendants /@ssn the attribute value of the attribute name ssn of the context node //@ssn like /@ssn but for all descendants /.. parent of context node /text() the text of the context node Examples: –/book/chapter/section –//chapter/* –//book/author/@*

40 CSE 6331 © Leonidas Fegaras XML40 Example text1 text2 text3 text4 a b cb d c b d /./aor /a--> [1] /./a./bor /a/b--> [2,4] /a/c--> [] /a/*/c--> [5,7] //b--> [2,6,4] //b/c--> [5] /a//c--> [5,7] 1 324 75 68 For example, /a/b returns nodes 2 and 4: text1 text2 text4

41 CSE 6331 © Leonidas Fegaras XML41 Predicates Many variations –//book[10]the tenth child node of the context node (tenth book) –//book[last()]the last child node of the context node (last book) –//book[author]true, if the book has at least one author –//book[author/name]true, if there is an author/name in the book –//book[author/name=“Smith”]true if the author name is Smith Examples /bib/book[@price < 100]/title /bib/book[author/text()] //author[name/firstname=“John”][name/lastname=“Smith”]/title /bib/book/author[name/firstname][address[zip=1234][city]]/name/lastname


Download ppt "CSE 6331 © Leonidas Fegaras XML1 Introduction to XML Leonidas Fegaras."

Similar presentations


Ads by Google