Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


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

1 Introduction to XML 1

2 XML XML started out as a standard data exchange format for the Web Yet, it has quickly become the fundamental instrument in the development of Web-based online information services and electronic commerce applications Today, many applications on the Web use XML for hosting and storing large amounts of structured data. XML standard is set and maintained by W3C (http://www.w3.org). 2

3 What is XML? XML stands for eXtensible Markup Language. XML is a markup language much like HTML. XML was designed to describe data; XML tags are not predefined in XML. You must define your own tags. XML is a portable, and an open standard (i.e., nonproprietary or fee-free) technology for data storage and exchange. XML Provides the ability to describe data in an open text-based format and deliver it using standard http protocol. 3

4 The main difference between XML and HTML XML is not a replacement for HTML. XML and HTML were designed with different goals. XML was designed to describe data and to focus on what data is. HTML was designed to display data and to focus on how data looks. 4

5 Creating a simple XML Document We want to create a XML document for the following information Kim Name Kim 1234 South Street, NY, USA Home Address 1234 South Street, NY, USA Vice President Job Title Vice President $175,000 Salary $175,000 5

6 XML Example Kim 34 South Street, NY, USA Vice President $175,000 XML documents are stored as files with the.xml extension An XML document contains:  Text that represents the data.  Elements that specify its structure. 6

7 XML Elements XML elements are similar to HTML elements, they consist of  Start tag  End tag  Content between the two tags Example: Kim 7

8 Tagging Data in XML $175,000 Considering the content only, it is not possible to understand what $175,000 stands for. The tag name Salary inform us that the content represents a salary. Similarly, an XML element might be tagged as gender, birth date, price,… XML is extensible, users create their own tags, the tag names are neither predefined nor limited. In HTML, the author of HTML documents can only use tags that are defined in the HTML standard (like and.....). 8

9 XML – Element Nesting Elements may be nested to any depth to provide structured data The previous XML document is modified to include more elements under the element. Kim 34 South Street NY USA Vice President $175,000 9

10 XML – Element Nesting Elements may be repeated to represent a list of values. Ali 12345 ….. 10 element repeated to list all students in a class

11 All XML elements must be properly nested Nesting XML tags improperly is a syntax error. In XML all elements must be properly nested within each other like this: Ali In HTML some elements can be improperly nested within each other like this: This text is bold and italic NOTE: It is considered a bad coding practice to nest tags improperly in HTML. 11

12 XML Root Element A valid XML document contains a single root element, which constitutes the top-level of nesting. The first tag in an XML document is the root tag. All the other elements must be nested within the root element...... 12 …

13 XML Element Names XML element names can be of any length and can contain letters, digits, underscores, hyphens and periods. XML element names must begin with either a letter or an underscore, and they should not begin with “ xml ” in any combination of uppercase and lowercase letters, as this is reserved for use in the XML standards. Using a white-space character in an XML element name is an error. Examples of invalid element names: $175,000 13

14 All XML elements must have a closing tag In an XML document, each start tag must have a matching end tag; omitting either tag is an error. In HTML some elements do not have to have a closing tag. The following code is legal in HTML: This is a paragraph This is another paragraph I n XML both tags must be included: Ali 12345 14

15 XML tags are case sensitive Unlike HTML, XML tags are case sensitive. Using different cases for the start tag and end tag names for the same element is a syntax error. With XML, the tag is different from the tag. Opening and closing tags must therefore be written with the same case: This is correct in XML 15

16 White Space in Element In XML, the white space in element is not truncated. He is my friend The above two XML statements are different. 16

17 XML - Attributes XML elements can have attributes, just like HTML. Attributes provide additional information about an element. Example: $175,000 175,000 17

18 Attribute used as primary key Mathew XML Guide 44.95 Saleem Java Handbook 12.00 18

19 Attribute Quotes With XML, it is illegal to omit quotation marks around attribute values. Incorrect attribute use: 12.00 Either single or double quotes can be used. 12.00 If the attribute value itself contains double quotes you can use single quotes. 19

20 White Space in Attribute In XML, the white space in the attribute is truncated or ignored. Ali The above two XML statements are the same. 20


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

Similar presentations


Ads by Google