200 likes | 342 Views
XML Extensible Markup Language. By: Gaurav Poudyal. Overview. XML Different XML Related Technologies XHTML XForms XQuery Conclusion. What is XML?. Markup language very similar to HTML How do they differ? HTML focuses on displaying data XML focuses on describing the data
E N D
XMLExtensible Markup Language By: Gaurav Poudyal
Overview • XML • Different XML Related Technologies • XHTML • XForms • XQuery • Conclusion
What is XML? • Markup language very similar to HTML • How do they differ? • HTML focuses on displaying data • XML focuses on describing the data • XML tags are not predefined as in HTML
Example Code • XML structures information • Code below is just information stored in XML tags <?xml version="1.0" encoding=""?> <journal> <message>Today is Wednesday and it’s windy.</message><br /> <message1>It is snowing outside</message1><br /> </journal>
XML • XML requires syntax just as in HTML 1) <?xml version="1.0" encoding=""?> 2) <journal> 3) <message>Today is Wednesday and it’s windy.</message> 4) <message1>It is snowing outside</message1> 5) </journal> • First line states XML version and the encoding • Tag journal is the root element • Lines 3 and 4 are child elements
XML • All tags must have a closing tag, unlike in HTML • XML tags are case sensitive • XML preserves the white space, unlike HTML Code: Today is Wednesday Displayed in html: Today is Wednesday Displayed in XML: Today is Wednesday
XML Elements • Elements can have relationships <class> <title>My Classes</title> <course>463</course> <subject>Client Server Web Applications <para>What is HTML</para> <para>What is XML</para> </subject> </class> • In the code above, class is the root element • Title, course, subject are child elements of class • Class is the parent element of title, course, subject • Title, course, subject are sister elements
XML with ASP • XML can be generated on server with ASP <% response.ContentType="text/xml" response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>") response.Write("<class>") response.Write("<title>My Classes</title>") response.Write("<course>Coms 463</course>") response.Write("<subject>Client Server Web Applications</subject>") response.Write("<para>What is HTML</para>") response.Write("<para>What is XML</para>") response.Write("</class>") %> • Must be saved as a .asp file
XML Related Technologies Few that I am covering in this presentation • XHTML • XForms • XQuery
XHTML • XHTML is also known as Extensible Hypertext Markup Language • XHTML is similar to HTML with stricter rules • XHTML needs proper syntax and formats • Nested elements • Proper tag names • Closed tag elements • Quoted and lowercase attribute names
Code Example Properly nested code: <ul> <li>Book</li> <li>Article <ul> <li>Online Article</li> </ul> </li> <li>Print</li> </ul>
Code Example Proper tag names: • Tags should be all lowercase • Cannot be <email> and <Email> • Cannot be <body> and <BODY> • All tags must be closed at end <email> <body>How are you?</body> </email>
Code Example Lower case attribute names and quoted value • Attribute name “width” must be lowercase • Value must be quoted, either single or double quotes <table width = "50%">
XForms • XForms are also known as XML Forms • More affluent • More flexible
Code Example <xforms> <model> <instance> <course> <cname/> <cid/> </course> </instance> <submission id="form1" method="get" action="submit.asp"/> </model> <input ref="cname"> <label>Course Name</label></input><br /> <input ref="cid"> <label>Course Iden</label></input><br /><br /> <submit submission="form1"> <label>Submit</label></submit> </xforms> • XML is used in XForm to define the form data • XML is also used to store and transport the data • Model defines the data • Instance defines the data that will be collected. These data will be stored in XML tags and transported to the destination provided • Submission defines how the data will be submitted • Rest of code for user interface
Control Elements • Input • Output • Submit • Secret • Select1 • Select • Upload and more…
XQuery • XQuery is also known as XML Query Language • Way to query XML data • Supported by all databases • Find information, build reports and search web documents
Code Example • Function extracts data from file; doc(“classes.xml”) • Path expressions; doc(“classes.xml”)/classes/class/title • Predicates; doc(“classes.xml”)/classes/class[maxstudents>20] (classes.xml) <?xml version="1.0" encoding="ISO-8859-1"?> <classes> <class category="Computers"> <title lang="en">Client Server</title> <teacher>Dr. Syed</teacher> <term>Fall 2005</term> <maxstudents>20</maxstudents> </class> <class category="Business"> <title lang="en">International Business</title> <teacher>John Doe</teacher> <term>Fall 2005</term> <maxstudents>50</maxstudents> </class> </classes>
XQuery • Syntax rules should be followed in XQuery • All elements, variable, attributes must be valid XML names • String value must be in quotes • Conditional statements can be used, such as if-then-else