Basics of XML Masters Project CS 490 Kevin
Basics of XML Masters Project CS 490 Kevin Murphy
What is XML n n n n e. Xtensible Markup Language Describes the structure of a document Based on SGML (Standard Generalized Markup Language) XML is focused on Content description Make your own elements Each element has a name and is contained in a tag. Portable, structured dynamic and descriptive Kevin Murphy
What XML Isn’t Static n A set of pre defined tags n Purpose of XML is to describe the general structure relating to the content inside a document—NOT that content’s actual appearance on the page or on the screen. n Kevin Murphy
Rules About Tags n Tags have a beginning and an ending tag, surrounding the text that they affect. n Closing tags have the tag name preceded by a slash (/). n All XML tags have a beginning and an end. n All XML tags are case insensitive. n Caution: If you forget to close a paired set of tags or you include a backslash or some other character rather than a forward slash, the tag won’t be closed, and the command will stay in effect. Kevin Murphy
Tag naming conventions In XML, tags can be invented that best describe the contents. n using markup that is readable by both humans and machines. n XML tags look something like this: <car> Chevy </car> n Kevin Murphy
The <XML> Tag This tag indicates that the content of this file is in XML language. n All the text and other XML tags and commands should be placed within beginning and ending XML tags. n Example: n <XML>. . . Web page. . . </XML> n Kevin Murphy
XML Formatting XML has to be well formed, This means the file must follow three basic rules: 1. The document starts with an XML declaration, <? xml version="1. 0"? >. 2. There is a root element in which all others are contained. 3. All elements must be properly nested. No overlapping is permitted. Kevin Murphy
Step 1: Creating an XML Page What is minimally needed: A. a basic text editor (to create your XML files) B. a browser to view them. IE 5 has an internal XML viewer and debugger. n File extension: Give the filename an extension of. xml n Example: file. xml n A good rule is to use lowercase names n Don’t use spaces or special characters—(Just letters and numbers are fine. ) n Kevin Murphy
Step 2: Viewing XML Source Pages You see the tags in your browser; as part of the final result. n Most Web browsers will allow you to view the XML source code. n In IE, go to the view menu and choose source. n Kevin Murphy
Step 3: View the Document Start up your Web browser n From the menu bar, select File, Open Page (or a similar command depending on the browser). n Kevin Murphy
Step 4: If your page didn’t work! Check your code n Look for opening and closing tags n If the text repeated in the browser, make sure the file was saved with the. xml extension. n After making corrections, save the file, and try viewing it again. n Kevin Murphy
Example <? xml version="1. 0"? > <student> <information> <fname>Kevin</fname> <lname>Murphy</lname> <email>kmurphy@neiu. edu</email> <sid>123321234</sid> <dept>cs</dept> <pass>neiu</pass> </information> </student> Kevin Murphy
Future of XML n This is a new language which Microsoft is still expanding. It is dynamic so there are many directions it can go, as with web the future is open. Kevin Murphy
- Slides: 13