Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 of Information TechnologyT2-Lecture-3

2 eXtensible Markup Language (XML) Part - I For Lecture Material/Slides Thanks to: www.w3schools.com

3 Synopsis Introduction to XML How Can XML be Used? XML Tree XML Syntax Rules XML Elements XML Attributes XML Namespaces XML Encoding Viewing XML Files Displaying XML with CSS 3 T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

4 Introduction to XML

5 5 XML was designed to transport and store data. HTML was designed to display data. Before we continue we should have a basic understanding of the HTML T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

6 What is XML? 6 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 T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

7 The Difference Between XML and HTML 7 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 HTML is about displaying information, while XML is about carrying information. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

8 XML Does Not DO Anything 8 Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store, and transport information. The following example is a note to Mumtaz, from Tariq, stored as XML: ◦ Mumtaz Tariq Reminder Don't forget to attend the party on weekend! The note above is quite self descriptive. It has sender and receiver information, it also has a heading and a message body. But still, this XML document does not DO anything. It is just information wrapped in tags. Someone must write a piece of software to send, receive or display it. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

9 With XML we Invent our Own Tags 9 The tags in the example above (like and ) are not defined in any XML standard. These tags are "invented" by the author of this XML example. That is because the XML language has no predefined tags. The tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like,, etc.). XML allows the author to define his/her own tags and his/her own document structure. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

10 XML is Not a Replacement for HTML 10 XML is a complement to HTML. It is important to understand that XML is not a replacement for HTML. In most web applications, XML is used to transport data, while HTML is used to format and display the data. The best description of XML is: XML is a software- and-hardware-independent tool for carrying information. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

11 Role of XML 11 XML is a W3C Recommendation W3C announced XML standard on February 10, 1998. XML is Everywhere XML is now as important for the Web as HTML is to the foundation of the Web. XML is the most common tool that facilitate the data transmissions between all sorts of applications. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

12 Use of XML

13 How Can XML be Used? 13 XML is used to describe the data storage and sharing. How XML Separates Data from HTML? If we need to display dynamic data in our HTML document, it will take a lot of work to re-edit the HTML each time the data is changed. With XML, data can be stored in separate XML files. This way we can concentrate on using HTML/CSS for display and layout of pages with updated or modified data. No changes in the HTML is required With a few lines of JavaScript code, we can read an external XML file and update the data content of our web page. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

14 XML Simplifies Data Sharing 14 One of the most time-consuming challenges for developers is to exchange data between incompatible systems over the Internet. XML data is stored in plain text format. That provides a software-and-hardware-independent way of storing data. So exchanging data as XML greatly reduces this complexity, since the data can be read by different incompatible applications. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

15 XML Simplifies Platform Changes 15 Upgrading to new systems (hardware or software platforms), is always time consuming. Large amounts of data must be converted and incompatible data is often lost. XML data is stored in text format. This makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing data. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

16 XML extends the data Availability. 16 Different applications can access the data from HTML pages and also from XML data sources. With XML, the data can be available to all kinds of "reading machines" (Handheld computers, voice machines, news feeds, etc.), and that make the data more available for blind people, or people with other disabilities. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

17 XML is Used to Create New Internet Languages 17 A lot of new Internet languages are created with XML. Examples: XHTML WSDL for describing available web services WAP and WML as markup languages for handheld devices RSS languages for news feeds RDF and OWL for describing resources and ontology SMIL for describing multimedia for the web T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

18 XML is a future tool 18 If XML is used with care and sense it will be a major platform for data exchange on web. In future we might receive word processors, spreadsheet applications and databases that can read each other's data in XML format, without any conversion utilities in between. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

19 XML Tree

20 XML Tree 20 XML documents form a tree structure that starts at "the root" and branches to "the leaves". Example XML Document XML documents use a self-describing and simple syntax: called declaration called declaration Mumtaz Tariq Reminder Don't forget to attend the party on weekend! The first line is the XML declaration. It defines the XML version (1.0) The next line describes the root element of the document (like saying: "this document is a note" ): T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

21 XML Tree… 21 The next 4 lines describe 4 child elements of the root (to, from, heading, and body): Mumtaz Tariq Reminder Don't forget to attend the party on weekend! And finally the last line defines the end of the root element: we can assume, from this example, that the XML document contains a note to Mumtaz from Tariq XML is self-descriptive? T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

22 XML Documents Form a Tree Structure 22 XML documents must contain a root element. This element is "the parent" of all other elements. The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree. All elements can have sub elements (child elements): ◦..... The terms parent, child, and sibling are used to describe the relationships between elements. Parent elements have children. Children at the same level are called siblings (brothers or sisters). All elements can have text content and attributes (just like in HTML). T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

23 XML Documents Form a Tree Structure… 23 T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

24 XML Documents Form a Tree Structure… 24 The above diagram may be represented in the XML as: ◦ Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 Learning XML Erik T. Ray 2003 39.95 The root element in the example is. All elements in the document are contained within. The element has 4 children:,,,. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

25 XML Syntax Rules

26 26 The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use. All XML Elements Must Have a Closing Tag In HTML, some elements do not have to have a closing tag: ◦ This is a paragraph. In XML, it is illegal to omit the closing tag. Note: You might have noticed from the previous example that the XML declaration did not have a closing tag. This is not an error. The declaration is not a part of the XML document itself, and it has no closing tag. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

27 XML Tags are Case Sensitive 27 XML tags are case sensitive. The tag is different from the tag. Opening and closing tags must be written with the same case: ◦ This is incorrect This is correct Note: "Opening and closing tags" are often referred to as "Start and end tags". Like HTML tags. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

28 XML Elements Must be Properly Nested 28 In HTML, you might see improperly nested elements: ◦ This text is bold and italic must In XML, all elements must be properly nested within each other: ◦ This text is bold and italic In the example above, "Properly nested" simply means that since the element is opened inside the element, it must be closed inside the element. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

29 XML Documents Must Have a Root Element 29 XML documents must contain one element that is the parent of all other elements. This element is called the root element...... T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

30 XML Attribute Values Must be Quoted 30 XML elements can have attributes in name/value pairs just like in HTML. In XML, the attribute values must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct: “date not quoted” “date not quoted” mumtaz tariq mumtaz tariq The error in the first document is that the date attribute in the note element is not quoted. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

31 Entity References 31 Some characters have a special meaning in XML. If you place a character like "<" (Less Than) 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 T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

32 Entity References… 32 There are 5 predefined entity references in XML: Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it to avoid inconsistency. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

33 Comments in XML 33 The syntax for writing comments in XML is similar to that of HTML. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

34 White-space is Preserved in XML 34 HTML truncates multiple white-space characters to one single white-space: T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

35 XML Stores New Line as LF 35 Windows applications stores a new line as: carriage return and line feed (CR+LF). Unix and Mac OS uses LF. Old Mac systems uses CR. XML stores a new line as LF. Well Formed XML ◦ XML documents that conform to the syntax rules above are said to be "Well Formed" XML documents. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

36 XML Elements

37 What is an XML Element? 37 What is an XML Element? An XML element is everything from the element's start tag to the element's end tag. (Including tags) An element can contain: other elements text attributes or a mix of all of the above... T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

38 What is an XML Element?... 38 Example Harry Potter J K. Rowling 2005 29.99 Learning XML Erik T. Ray 2003 39.95 T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

39 What is an XML Element?... 39 In the example above, and have element contents, because they contain other elements. also has an attribute (category="CHILDREN").,,, and have text content because they contain text. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

40 Empty XML Elements 40 An alternative syntax can be used for XML elements with no content: Instead of writing a book element (with no content) like this: ◦ It can be written like this: ◦ This sort of element syntax is called self-closing. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

41 XML Naming Rules 41 XML elements must follow 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, there are no reserve words except XML !! T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

42 Best Naming Practices 42 Make names descriptive:,. Make names short and simple, like this: not like this:. Avoid "-". If you name something "first-name," some software may think you want to subtract name from first. Avoid ".". If you name something "first.name," some software may think that "name" is a property of the object "first." Avoid ":". Colons are reserved to be used for something called namespaces (will be taught later). Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software doesn't support them. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

43 Naming Styles 43 There are no naming styles defined for XML elements. But here are some commonly used: If you choose a naming style, it is good to be consistent! 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. T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com

44 Common Errors for Element Naming Do not use white space when creating names for elements Element names cannot begin with a digit, although names can contain digits Only certain punctuation allowed – periods, colons, and hyphens T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com 44

45 Main Components of an XML Document Elements: Attributes: Entities: < (<) T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com 45

46 Review: The Basic Rules XML is case sensitive All start tags must have end tags Elements must be properly nested XML declaration is the first statement Every document must contain a root element Attribute values must have quotation marks Certain characters are reserved for parsing T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com 46

47 The End XML Part-I T2-Lecture-3 Thank You 1-47 T2-Lecture-3 Ahmed Mumtaz Mustehsan www.w3schools.com


Download ppt "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."

Similar presentations


Ads by Google