What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data XML.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Chapter 7 An Introduction to XML.
Ali Alshowaish w3schools. XML documents use a self-describing and simple syntax: The first line is the XML declaration. It defines the XML version (1.0)
XML –EXtensible Markup Language –Designed to transform and store data –We will learn difference between xml and html.
XML Craig Stewart Dr. Alexandra I. Cristea
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
An Introduction to XML Based on the W3C XML Recommendations.
XML Unit 6 October 31. XML, review XML is used to markup data Used to describe information Uses tags like HTML –But all tags are user-defined –Must be.
INF201 Fall2010 Intro. to Info. Technologies Department of Informatics University at Albany – SUNY Original Source: w3schools.com Prepared by Xiao Liang,
IS 373—Web Standards Todd Will
Sistemi basati su conoscenza XML Prof. M.T. PAZIENZA a.a
XML CS 105. What is XML? XML stands for Extensible Markup Language. XML is a markup language like HTML. XML was designed to describe data. You must define.
Sistemi basati su conoscenza XML Prof. M.T. PAZIENZA a.a
XML(EXtensible Markup Language). XML XML stands for EXtensible Markup Language. XML is a markup language much like HTML. XML was designed to describe.
XML Primer. 2 History: SGML vs. HTML vs. XML SGML (1960) XML(1996) HTML(1990) XHTML(2000)
Introduction to XML: Yong Choi CSU Bakersfield.
Introduction to XML Rashmi Kukanur. XML XML stands for Extensible Markup Language XML was designed to carry data XML and HTML designed with different.
Introduction to XML Chien-Chung Shen CIS, UD
Introduction XML Dr. Qusai Abuein June, 2012 XML Dr. Qusai Abuein 1 Part (I) XML Basics.
Introduce of XML Xiaoling Song CS157A. What is XML? XML stands for EXtensible Markup Language XML stands for EXtensible Markup Language XML is a markup.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
 Introduction to XML Introduction to XML  Features of XML Features of XML  Syntax of XML Syntax of XML  Syntax rules of XML document Syntax rules.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Pemrograman Berbasis WEB XML -Aurelio Rahmadian- Sumber: w3cschools.com.
XML Technologies Surekha Akula
Introduction to XML 1. XML XML started out as a standard data exchange format for the Web Yet, it has quickly become the fundamental instrument in the.
XHTML,XML M.Abdullah Mrian. What is the XHTML Why XHTML ?
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
XML TUTORIAL Portions from w3 schools By Dr. John Abraham.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
How do I use HTML and XML to present information?.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
XML eXtensible Markup Language. Topics  What is XML  An XML example  Why is XML important  XML introduction  XML applications  XML support CSEB.
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML.
Consuming eXtensible Markup Language (XML) feeds.
1 Dr Alexiei Dingli XML Technologies XML. 2 XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry.
XML Documents Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Elements Attributes Comments PI Document.
WEB APPLICATION DEVELOPMENT For More visit:
Consuming eXtensible Markup Language (XML) feeds.
XML 2 Prepared by / Nael Alian Uinverity of Palestine Re. 1.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of Computer Science, Mathematics and Physics University.
1 Credits Prepared by: Rajendra P. Srivastava Ernst & Young Professor University of Kansas Sponsored by: Ernst & Young, LLP (August 2005) XBRL Module Part.
An Introduction to XML Sandeep Bhattaram
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
What it is and how it works
XML Introduction. Markup Language A markup language must specify What markup is allowed What markup is required How markup is to be distinguished from.
XML Basics A brief introduction to XML in general 1XML Basics.
EXtensible Markup Language XML Question: What is the most common use of XML Answer: As a buzzword to spice up a resume.
ASHIMA KALRA  INTRODUCTION OF XML INTRODUCTION OF XML  XML FEATURES XML FEATURES  XML SYNTAX XML SYNTAX  XML ELEMENTS XML ELEMENTS  XML ATTRIBUTES.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
IS444: Modern software development tools Dr. Azeddine Chikh.
XML. HTML Before you continue you should have a basic understanding of the following: HTML HTML was designed to display data and to focus on how data.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
CHAPTER NINE Accessing Data Using XML. McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Introduction The eXtensible.
XML Introduction to XML Extensible Markup Language.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
XML intro. What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display.
XML BASICS and more…. What is XML? In common:  XML is a standard, simple, self-describing way of encoding both text and data so that content can be processed.
Database Systems – SQL XML XML stands for Extensible Markup Language
Javascript & jQuery XML.
What is XML?.
Allyson Falkner Spokane County ISD
Presentation transcript:

What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptive XML is a W3C Recommendation

XML is not a replacement for HTML. XML and HTML were designed with different goals: –XML was designed to transport and store data, with focus on what data is. –HTML was designed to display data, with focus on how data looks.

XML does not DO anything. XML was created to structure, store, and transport information. But still, this XML document does not DO anything. It is just pure information wrapped in tags.

Example xml1.xml 5 points for someone Chetan B. India

XML trees An xml document is a hierarchical structure called an xml tree which consist of various kinds arranged as a tree.

CATLOG BOOK TITLEAUTHORCOUNTRYPRICEYEAR

An XML document contains XML Elements. Harry Potter J K. Rowling Learning XML Erik T. Ray

XML (tag) Naming Rules XML elements must follow these naming rules: Names can contain letters, numbers, and other characters Names cannot start with a number or punctuation character Names cannot start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces Any name can be used, no words are reserved.

Best Naming Practices Make names descriptive. Names with an underscore separator are nice:,. Names should be short and simple, like this: not like this:. Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first. Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first.“ Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later). XML documents often have a corresponding database. A good practice is to use the naming rules of your database for the elements in the XML documents. Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software vendor doesn't support them.

XML Elements are Extensible Harry Potter J K. Rowling st Learning XML Erik T. Ray

Xml syntax All tags tag should have closing tag. All tags are case sensitive. Xml elements must be properly nested Xml document must have root element is must. Attributes must be in double quotes.

Entity References Some characters have a special meaning in XML. If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.

This will generate an XML error: if salary To avoid this error, replace the "<" character with an entity reference: if salary < 1000 then

There are 5 predefined entity references in XML: < <less than > >greater than & ampersand &apos; 'apostrophe " "quotation mark

Comments in XML The syntax for writing comments in XML is similar to that of HTML. White-space is Preserved in XML HTML truncates multiple white-space characters to one single white-space: HTML: Hello my name is Tove Output: Hello my name is Tove.

Xml elements attributes XML elements can have attributes in the start tag, just like HTML. Attributes provide additional information about elements.

or like this: If the attribute value itself contains double quotes you can use single quotes, like in this example: Or you can use character entities:

Avoid XML Attributes? Some of the problems with using attributes are: attributes cannot contain multiple values (elements can) attributes cannot contain tree structures (elements can) attributes are not easily expandable (for future changes) Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.

Id Tove Jani Reminder Don't forget me this weekend! Jani Tove Re: Reminder I will not

Xml and css With css you can add display information to xml. Eg Cd_catlog.css Cd_catlog.xml Cd_catlog1.xml

Other way is XSLT

Xsl : extensible stylesheet language. Xslt : xsl transform. (language for xml transformation ) XSLT is a language for transforming XML documents into XHTML documents or to other XML documents.

CSS = Style Sheets for HTML –HTML uses predefined tags, and the meaning of each tag is well understood. –The tag in HTML defines a table - and a browser knows how to display it. –Adding styles to HTML elements are simple. Telling a browser to display an element in a special font or color, is easy with CSS. XSL = Style Sheets for XML –XML does not use predefined tags (we can use any tag-names we like), and therefore the meaning of each tag is not well understood. –A tag could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it. –XSL describes how the XML document should be displayed!

XSLT = XSL Transformations XSLT is the most important part of XSL. XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element. With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more. A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree.

Correct Style Sheet Declaration The root element that declares the document to be an XSL style sheet is or. <xsl:stylesheet version="1.0" xmlns:xsl=" or

XSLT Element An XSL style sheet consists of one or more set of rules that are called templates. A template contains rules to apply when a specified node is matched

The element is used to build templates. The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document).

My CD Collection Title Artist..

XSLT Element The element is used to extract the value of a selected node.

Book.xml Empire Burlesque Bob Dylan USA Columbia

My Collection Title author

The Element The XSL element can be used to select every XML element of a specified node-set:

My CD Collection Title Artist

The Element To put a conditional if test against the content of the XML file, add an element to the XSL document. Syntax...some output if the expression is true...

My CD Collection Title Artist

The element is used to sort the output.

My CD Collection Title Artist

A JavaScript Solution We have explained how XSLT can be used to transform a document from XML to XHTML. We did this by adding an XSL style sheet to the XML file and let the browser do the transformation. Even if this works fine, it is not always desirable to include a style sheet reference in an XML file (e.g. it will not work in a non XSLT aware browser.) A more versatile solution would be to use a JavaScript to do the transformation. By using a JavaScript, we can: do browser-specific testing use different style sheets according to browser and user needs

function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(""); return xhttp.responseXML; } xml=loadXMLDoc("cd_catalog.xml"); path="/CATALOG/CD[PRICE > 9]/TITLE" // code for IE if (window.ActiveXObject) {var nodes=xml.selectNodes(path); for (i=0;i<nodes.length;i++) { document.write(nodes[i].childNodes[0].nodeValue); document.write(" "); } }

// code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null); var result=nodes.iterateNext(); while (result) { document.write(result.childNodes[0].nodeValue); document.write(" "); result=nodes.iterateNext(); }

Try2.html Try3.html

What is XPath? XPath is a syntax for defining parts of an XML document XPath uses path expressions to navigate in XML documents XPath contains a library of standard functions XPath is a major element in XSLT XPath is a W3C recommendation

XPATH terminologies Parent Children Siblings Ancestors Descendants

XPATH Loading the XML Document Using XMLHttpRequest to load XML documents is supported in all modern browsers. Code for most modern browsers: var xmlhttp=new XMLHttpRequest() Code for old Microsoft browsers (IE 5 and 6): var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

Selecting Nodes Internet Explorer uses the selectNodes() method to select nodes from the XML document: xmlDoc.selectNodes(xpath); Firefox, Chrome, Opera and Safari use the evaluate() method to select nodes from the XML document: xmlDoc.evaluate(xpath, xmlDoc, null, XPathResult.ANY_TYPE,null); var xpathResult = document.evaluate( xpathExpression, contextNode, namespaceResolver, resultType, result );

xpathExpression: A string containing the XPath expression to be evaluated. contextNode: A node in the document against which the xpathExpression should be evaluated, including any and all of its child nodes. The document node is the most commonly used. namespaceResolver: A function that will be passed any namespace prefixes contained within xpathExpression which returns a string representing the namespace URI associated with that prefix. This enables conversion between the prefixes used in the XPath expressions and the possibly different prefixes used in the document. The function can be either: –null, which can be used for HTML documents or when no namespace prefixes are used. Note that, if the xpathExpression contains a namespace prefix, this will result in a DOMException being thrown with the code NAMESPACE_ERR. –A custom user-defined function. See the Using a User Defined Namespace Resolver section in the appendix for details. resultType: A constant that specifies the desired result type to be returned as a result of the evaluation. The most commonly passed constant is XPathResult.ANY_TYPE which will return the results of the XPath expression as the most natural type. There is a section in the appendix which contains a full list of the available constants. They are explained below in the section "Specifying the Return Type." result: If an existing XPathResult object is specified, it will be reused to return the results. Specifying null will create a new XPathResult object.

The following example selects all the title nodes: Example /bookstore/book/title Select the title of the first book The following example selects the title of the first book node under the bookstore element: Example /bookstore/book[1]/title Select title nodes with price>35 The following example selects all the title nodes with a price higher than 35: Example /bookstore/book[price>35]/title Try4.html

Expressions Path ExpressionResult bookstoreSelects all the child nodes of the bookstore element /bookstoreSelects the root element bookstore Note: If the path starts with a slash ( / ) it always represents an absolute path to an element! bookstore/bookSelects all book elements that are children of bookstore //bookSelects all book elements no matter where they are in the document bookstore//bookSelects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element all attributes that are named lang

Predicates –Finds exact node

Path ExpressionResult /bookstore/book[1]Selects the first book element that is the child of the bookstore element. Note: IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!! /bookstore/book[last()]Selects the last book element that is the child of the bookstore element /bookstore/book[last()-1]Selects the last but one book element that is the child of the bookstore element /bookstore/book[position()<3]Selects the first two book elements that are children of the bookstore element all the title elements that have an attribute named lang all the title elements that have an attribute named lang with a value of 'eng' /bookstore/book[price>35.00]Selects all the book elements of the bookstore element that have a price element with a value greater than /bookstore/book[price>35.00]/titleSelects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00

Wild card characters Path ExpressionResult /bookstore/*Selects all the child nodes of the bookstore element //*Selects all elements in the document all title elements which have any attribute

Selecting several paths Path ExpressionResult //book/title | //book/priceSelects all the title AND price elements of all book elements //title | //priceSelects all the title AND price elements in the document /bookstore/book/title | //priceSelects all the title elements of the book element of the bookstore element AND all the price elements in the document

SAX - Simple API for XML Parsing Being the first in the evolution ladder, it obviously had only the basic support for XML processing. It is an event-based technology, which uses callbacks to load the parts of the XML document in a sequential way. This effectively means you can't go back to some part which was read/processed previously - if you do have such a requirement then you would need to store/manage the relevant data yourself. Since this API does require to load the entire XML doc and also because it offers only a sequential processing of the doc hence it is quite fast. Another reason of it being faster is that it does not allow modification of the underlying XML data.

DOM - Document Object Model The Java binding for DOM provided a tree-based representation of the XML documents - allowing random access and modification of the underlying XML data. Not very difficult to deduce that it would be slower as compared to SAX. The event-based callback methodology was replaced by an object- oriented in-memory representation of the XML documents.

SAXDOM Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation. Parses node by node Stores the entire XML document into memory before processing Doesn’t store the XML in memoryOccupies more memory We cant insert or delete a nodeWe can insert or delete nodes Top to bottom traversingTraverse in any direction. SAX is an event based parserDOM is a tree model parser SAX is a Simple API for XMLDocument Object Model (DOM) API import javax.xml.parsers.*; import org.xml.sax.*; import org.xml.sax.helpers.*; import javax.xml.parsers.*; import org.w3c.dom.*; doesn’t preserve commentspreserves comments SAX generally runs a little faster than DOM If we need to find a node and doesn’t need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.