Download presentation
Presentation is loading. Please wait.
1
XML and Internet Databases
Dawood Al-Nasseri Wade Meena MIS 409 Dr.Sumali Conlon
2
Outline What is XML . History of XML . The definition of xml .
What I can do with XML . Top five reasons to use XML. Xml query languages . Xpath . Xquery .
3
What is XML ? XML stands for ? X eXtensible M Markup L Language
4
History -It begins with the development of Standardised Generalised Markup Language (SGML) by Charles Goldfarb, along with Ed Mosher and Ray Lorie . - Founded in 1970. - In United States , Armonk, North Castle, NY - IBM’s headquarter.
5
XML -XML is a software- and hardware-independent tool for storing and transporting data. - A metalanguage which allows users to define their own customized markup languages, especially in order to display documents on the Internet. - XML is a markup language much like HTML. - XML was designed to be self-descriptive.
6
What can I do with XML ? XML Separates Data from Presentation -XML does not carry any information about how to be displayed. -The same XML data can be used in many different presentation scenarios. -Because of this, with XML, there is a full separation between data and presentation.
7
What can I do with XML ? XML Separates Data from HTML.
-When displaying data in HTML, you should not have to edit the HTML file when the data changes. -With XML, the data can be stored in separate XML files. -With a few lines of JavaScript code, you can read an XML file and update the data content of any HTML page.
8
Store and Retrieve Data
Just about every software application needs to store some data. There are look-up tables, work files, preference settings, and so on. XML makes it very easy to do this. Say, for example, you've created a calendar program and you need a way to store holidays. You could hard code them, of course, but that's kind of a hassle since you'd have to recompile the program if you need to add to the list.
9
Example : XML <caldata> <holiday type="international"> <name>New Year's Day</name> <date><month>January</month><day>1</day></date> </holiday> <holiday type="personal"> <name>Erik's birthday</name> <date><month>April</month><day>23</day></date> </holiday> <holiday type="national"> <name>Independence Day</name> <date><month>July</month><day>4</day></date> </holiday> <holiday type="religious"> <name>Christmas</name> <date><month>December</month><day>25</day></date> </holiday> </caldata>
10
Top Five Reasons to Use XML
11
XML is an international standard
- XML is a document standard that is maintained by the W3C, an organization that is responsible for Web standards. XML documents are vendor-neutral, and they are not tied to one application or one company. - There are many different document types that are available for writers. -These document types are often proprietary and can only be created in software that is compatible with the type of document. XML documents can be created in any XML editor, so you can create an XML file in one XML editor and open and edit it in any other XML editor. XML documents can also be created in a text editor such as Notepad.
12
The name says it all ; eXtensible.
XML uses XML elements or tags to define document structure. By defining the document structure, you can then use outside processes such as style sheets to manipulate and reuse content. By separating content from display, you can use a single source of content and use it in many different contexts. XML does not have a fixed number of tags or elements, as HTML does, but it is extensible, allowing the document designer to define meaningful tags. By using XML, developers can develop a markup language that is suitable for their purpose. For example, technical writers that choose to use DITA for documentation can extend the default elements that are available in DITA. Writers can define new elements that they need for their specific needs. This ability to define custom elements makes XML extremely versatile.
13
One size fits all users. Content re-use saves companies money and makes authors more efficient. XML supports and promotes these sorts of processes by being flexible and modular. You can create content, and then re-use that content in different documents. XML documents can be manipulated to suit the needs of different users. It is quite easy to apply different style sheets to an XML document to manipulate content for different audiences or output different types of documents.
14
You can separate content from display formatting.
-XML allows you to separate content from format. The formatting of the XML document is inside a separate style sheet. This separation allows you to easily maintain and update formatting as needs change. It is easy to maintain a consistent style for all documents when the content is separate from the formatting.
15
XML can make your writing efficient
XML is very helpful when you publish in more than one language and when you publish different types of documents from the same source. By storing content in XML source files, you can reduce translation costs. Then if you need to create documents in several languages, you can publish your files by just clicking a button. You don’t need to fiddle with the formatting of the documents. This formatting is automatically applied when you publish your source XML files.XML also makes it easier to maintain content. After the content is updated, you click the button and all of your revised documents are published.
16
How does this work To illustrate the benefits of separating structure from display, we can look at a common scenario that may occur in large and small offices on a regular basis. A document is created that will be needed in several output formats. This document will be needed in the following output formats: WebHelp PDF CHM If you were using traditional methods, you would need a separate source document for each output type. When you separate structure from format using XML, you only need one source for the content. The formatting of the different outputs resides in separate style sheets. Once you have developed these style sheets to format the documents, you only need to update the source files when you need to revise the content. Publish your source files with one click, and all of the document types are published. No more “copy and paste” between different documents!
17
IS XML Useful for MIS students ?
-In a world of disparate computing technologies MIS students are in need for many technical and programming skills. - “Knowing XML” can mean a couple of different things. - XML is used for configuration if you are using a framework like Spring or Hibernate, Android development, and many other platforms. - XML can be used on the server-side and then converted into JSON for a web client. This allows you to validate using XML schemas. -The first is understanding the basic syntax. It is a prerequisite for writing XHTML, SVG, Atom, RSS, and a host of other languages which are XML applications. - The second builds upon the first and is an understand of how to develop your own XML applications, i.e. custom data storage or exchange formats. 1down vo 1down vote"Knowing XML" can mean a couple of different things.
18
Xml Query Languages -XPath - XQuery
19
XPath XPath (XML Path Language) is a query language for selecting nodes from an XML document. In addition,XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium (W3C).
20
Common Querying Tasks Filter, select XML values
Navigation, selection, extraction Merge, integrate values from multiple XML sources, Joins, aggregation. -Transform.
21
XML data: Running example
XML input: <book year=“1996”> <title> HTML </title> <author> <last> Lee </last> <first> T. </first></author> <author> <last> Smith</last> <first>C.</first></author> <publisher> Addison-Wesley </publisher> <price> </price> </book> <book year=“2003”> <title> WMD </title> <author> <last> Bush</last> <first> G.</first></author> <publisher> white house </publisher>
22
DTD ( Document Type Definition)
<!ELEMENT bib (book*) > <!ELEMENT book (title, (author+ | editor+), publisher?, price?) > <!ATTLIST book year CDATA #required > <!ELEMENT author (last, first)> <!ELEMENT editor (last, first, affiliation)> <!ELEMENT publisher (#PCDATA) > ….
23
Data model Node-labeled, ordered tree
24
XPath -Navigating an XML tree and finding parts of the tree (node selection and value extraction). - Given an XML tree T and a context node n, an XPath query Q returns -the set of nodes reachable via Q from the node n in T – if Q is a unary query. -truth value indicating whether Q is true at n in T – if Q is a Boolean query. Implementations: XALAN, SAXON, Berkeley DB XML, Monet XML – freeware, which you can play with. A major element of XSLT, XQuery and XML Schema.
25
XPath constructs XPath query Q:
–Tree traversal: downward, upward, sideways –Relational/Boolean expressions: qualifiers (predicates) –Functions: aggregation (e.g., count), string functions //author[last=“Bush”] //book[author/last=“Bush”]/title | //book[author/last=“Blair”]/title
26
Downward traversal Syntax:
Q ::= | l | @l | Q/Q | Q | Q | //Q | /Q | Q[q] q ::= Q | Q op c | q and q | q or q | not(q) .: self, the current node l: either a tag (label) or *: wildcard that matches any label @l: attribute /, |: concatenation (child), union //: descendants or self, “recursion” [q]: qualifier (filter, predicate) op: =, !=, <=, <, >, >=, > c: constant and, or, not(): conjunction, disjunction, negation Existential semantics: /bib/book[author/last=“Bush”].
27
Examples: parent/child: /bib/book
ancestor//descendant: bib//last, //last wild card: bib/book/* attributes: attributes with wild cards: union: editor | author Are book/author and //author “equivalent” at context nodes (1) root, (2) book, (3) author?
28
Upward traversal Syntax:
Q ::= | ../Q | ancestor ::Q | ancestor-or-self::Q../: parent ancestor, ancestor-or-self: recursion Example: //author[../title = “WMD”]/last find the last names of authors of books with the title “WMD” ancestor :: book[//last=“Bush”] find book ancestors with “Bush” as its last descendant Are the following equivalent to each other (context node: a book)? ../book/author, ./author .
29
Sideways Syntax: Q ::= | following-sibling ::Q | preceding-sibling::Q üfollowing-sibling: the right siblings üpreceding-sibling: the left siblings üposition function (starting from 1): e.g., //author[position( ) < 2] Example: üfollowing-sibling :: book [//last=“Bush”] find the books that are right siblings and are written by Bush üpreceding-sibling :: book[//last=“Bush”] find the books that are left siblings and are written by Bush
30
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, binary, etc.).
31
FLWR Expressions For, Let, Where, OrderBy, return
Q1: Find titles and authors of all books published by Addison-Wesley after 1991. <answer>{ for $book in /bib/book where > and $book/publisher=‘Addison-Wesley’ return <book> <title> {$book/title } </title>, for $author in $book/author return <author> {$author } </author> </book> }</answer> üfor loop; $x: variable üwhere: condition test; selection return: evaluate an expression and return its value
32
join Find books that cost more at Amazon than at BN <answer>{
let $amazon := doc(“ $bn := doc(“ for $a in $amozon/books/book, $b in $bn/books/book where $a/isbn = $b/isbn and $a/price > $b/price return <book> {$a/title, $a/price, $b/price } <book> }</answer> let clause join: of two documents
33
Conditional expression
Q2: Find all book titles, and prices where available <answer>{ for $book in /bib/book return <book> <title> {$book/title } </title>, { if $book[price] then <price> {$book/price } </price> else ( ) } </book> }</answer>
34
Summary and Review -Query languages for XML -XPath: navigating an XML tree -XQuery: XML query language -Very powerful (as opposed to relational algebra); however, query processing/optimization is hard – open issue!
35
JSON -JSON (JavaScript Object Notation) is a lightweight data-interchange format -JSON text format that is completely language Independent - JSON code is valid JavaScript -JSON is built on two structures: A collection of name/value pairs 2. An ordered list of values
36
JSON: Example “firstName”: “John”, “lastName”: “Smith”, “Address”:
“streetAddress”: “1 Access Blvd”, “City”: “Oxford”, “State”: “MS” “postalCode”: 10021 },
37
Continued “phoneNumbers”: [ “ ”, “ ” ] }
38
JSONRequest JSONRequest is proposed as a new browser service that allows for 2-way data exchange with any JSON data server without exposing users or organization to harm. Exchanges data between scripts on pages with JSON servers in the web. It is hoped that browser makers will build this feature into their products in order to enable the next advance in web application development. JSONRequest is a global JavaScript object. It provides three methods: post, get, and cancel. JSONRequest works only with JSON text responses will be rejected unless they contain a JSONRequest content type
39
Comparing Criteria of JSON & XML
Speed: Each format has its advantages and disadvantages JSON is smaller than XML JSON is part of JavaScript code, It needs less time to parse data thank the time for XML JSON is faster than XML in AJAX
40
Comparing Criteria of JSON & XML
Fetching Data from Server: XML uses XMLHttpRequest to fetch data from Server JSON can fetch data from Server with and without XMLHttpRequest in AJAX, it also uses JSONRequest Speed fetching data is almost same, but speed parsing fetched data is different
41
XML SCHEMA In XML Schema that describes the structure of an XML document, just like a DTD. An XML document with correct syntax is called "Well Formed". An XML document validated against an XML Schema is both "Well Formed" and "Valid".
42
Why Use an XML Schema? Why should you use an XML Schema?
In XML Schema, your XML files can carry a description of its own format. With XML Schema, independent groups of people can agree on a standard for interchanging data. With XML Schema, you can verify data.
43
XML Schemas Support Data Types
The greatest strength of XML Schemas is the support for data types: It’s easier to describe document content It’s easier to define restrictions on data It’s easier to validate the correctness of data It’s easier to convert data between different data types
44
XML Schemas use XML Syntax
A Great strength about XML Schemas is that they are written in XML: Don't have to learn a new language Can use your XML editor to edit your Schema files Can use your XML parser to parse your Schema files Can manipulate your Schemas with the XML DOM Can transform your Schemas with XSLT
45
XSD Example <?xml version="1.0"?>
<xs:schema xmlns:xs=" <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/>
46
XSD Example <xs:element name="body" type="xs:string"/>
</xs:sequence> </xs:complexType> </xs:element> </xs:schema>
47
XML Schemas Secure Data Communication
When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content. The sender in XML Schemas can describe the data in a way that the receiver will understand. A date like: " " can be interpreted as 1.OCTOBER in some countries and in others as 10.January. An XML element with a data type like this: <date type="date"> </date> ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".
48
XML Schemas (continued)
- XML Schemas is one of the alternatives to DTD It has 2 purposes: 1. Specify the structure of its instance XML documents 2. Specify the data type of every element and attribute of its instance XML documents - Schemas are written using a namespace: - Every XML schema has a single root, schema The schema element must specify the namespace for schemas as its xmlns:xsd attribute - Every XML schema itself defines a tag set, which must be named targetNamespace = "
49
Document Type Definition (DTD)
What is it? Document Type Definition (DTD) is a set of markup declarations that define a document type for an SGML-family markup language (SGML, XML, HTML). -It Defines the structure of an XML document Only the elements defined in a DTD can be used in an XML document - It can be internal or external.
50
Continued.. - Document Type Definition (DTD) defines the structure of a “valid” XML document - Processing overhead is incurred when validating XML with a DTD
51
Why Use a DTD? With a DTD, independent groups of people can agree on a standard DTD for interchanging data. An application can use a DTD to verify that XML data is valid.
52
Example of an Internal DTD
<?xml version=“1.0”?> Example of an Internal DTD <!DOCTYPE invoice [ <!ELEMENT invoice (sku, qty, desc, weight) > <!ELEMENT sku (#PCDATA) > <!ELEMENT qty (#PCDATA) > <!ELEMENT desc (#PCDATA) > <!ELEMENT price (#PCDATA) > }> <invoice> <sku>54321</sku> <qty>55</qty> <desc>Big dawg eating a bone</desc> <weight>75.95</weight> </invoice>
53
Referenced External DTD
<?xml version=“1.0”> Referenced External DTD <!DOCTYPE invoice SYSTEM “invoice.dtd”> <invoice> <sku>54321</sku> <qty>55</qty> <desc>Big dawg eating a bone</desc> <price>13.95</price> </invoice>
54
Document Type Declarations
4 types of Declarations: Element type declarations Attribute List Declarations Entity declarations Notation declarations
55
Element Type Declarations
Three types of elements - Empty elements - Any elements - Mixed elements
56
Empty Elements An element that can’t contain any content
HTML image tag in xml would typically be empty, such as <image></image> or <image/> empty elements are more useful with the use of attributes
57
Any Element An element that can contain any content.
it is recommended not to get into the habit declaring elements with the ANY keyword useful when transferring a lot of mixed or unknown data
58
Mixed Element Elements that can contain a set of content alternatives
Separate the options with the “or” symbol “|” <!ELEMENT test <#PCDATA | name>
59
Structure Symbols •Parenthesis (samp1, samp2) - The element must contain the sequence samp1 and samp2 •Comma (samp1,samp2,samp3) - The element must contain samp1,samp2 and samp3 in that order •Or (samp1|samp2|samp3) - The element can contain samp1, samp2 or samp3 •? samp1? - Element might contain samp1, if it does it can only do it once •* samp1* - Element can contain samp1 one or more times • samp1+ - Element must contain samp1 at least once none samp1 - Element must contain samp1
60
Attribute Rules The Attribute values must be placed in “ “ - in HTML this is only required id the attribute contains the space character The Attribute values are not processed by the XML parser - this means the values can’t be automatically checked by the parser
61
XML Element Attributes
XML tags can contain attributes similar to attributes in HTML tags Attributes are usually used to provide processing information to the XML application (the application that is going to consume the XML) HTML EXAMPLE: <h1> align=”center”>XML Example<h1> <table width=page><.table>
62
Attributes or Elements?
•Is it better to use attributes or to just make additional XML elements –there are no set rules when to use one over the other -Experience is the key to getting better – To help you decide: -Attribute values are not parsed can contain special characters that aren’t allowed in elements drawback - they cannot be validated by the parser –must be validated by additional code in the application
63
Example.. <?xml version=“1.0” ?> <invoice> <date> <month>12</month <day>22</day> <year>2002</year> </date> <sku>12345</sku> <qty>55</qty> <desc>Left handed monkey wrench</desc> <price>14.95</price> </invoice>
64
DTD Validation How to test for DTD errors while loading XML document? Since DTD is the grammar for XML, XML is a parse tree of its DTD. Thus, we can use a XML parser to check if the XML is valid.
65
References --https://www.w3schools.com/xml/xml_usedfor.asp
- Slides courtesy Wenfei Fan, Univ Edinburgh and Bell Labs). - -Slides courtesy of Addison Wesley Longman, Inc. - W3C standard: Anderson, T. (2004) Introducing XML. Retrieved on February 29, 2008 from Cover R. (2007) XML and Compression. Retrieved on February 29, 2008 from Harrusi, S., Averbuch, A. & Yehudai, A. (2006) XML Syntax Conscious Compression. Proceedings of the 2006 Data Compression Conference. 10 – 19. Slides courtesy Document Type Definition DTDs CS-328
66
Thank You!
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.