Download presentation
Presentation is loading. Please wait.
1
XML Partha Pratim
2
eXtensible Markup Language
XML is a kind of a ‘Mark-up Language.’ Any markup language have: Tags and Elements: ex. <p> is a tag. and <p> with the text here </p> --- is an element. Attributes: ex. <tagname attribute = “value”>
3
“Standardized Generalized Markup Language.” (SGML)
All Mark up languages are created from: “Standardized Generalized Markup Language.” (SGML) SGML became an international standard in 1986. SGML allows the authors to create and describe additional elements and attributes in a mark up language. HTML came from SGML, as did XML
4
HTML : Some Drawbacks Has fixed set of tags. You cannot create your own. Is only a presentation technology. Does not carry information about the meaning of the content held within its tags. Flat. No precedence among tags. High traffic volume. Ex. Sending large general sets of data across a network when only a small amount is required.
5
Closer Look. XML was designed to describe data
Tags are not predefined in XML. You must define your own tags XML uses a Document Type Definition (DTD) or an XML Schema to describe the data XML with a DTD or XML Schema is designed to be self-descriptive
6
The main difference between XML and HTML
XML was designed to carry data. 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. HTML is about displaying information, while XML is about describing information
7
XML tags are case sensitive.
Syntax XML tags are case sensitive. <?xml version="1.0" encoding="ISO "?> <note> Root element <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> End of Root element.
8
Syntax (cont.) General Form: <root> <child>
<subchild>.....</subchild> </child> </root> Example with attributes: <?xml version="1.0" encoding="ISO "?> <note date="12/11/2002"> <to>Tove</to> <from>Jani</from> </note>
9
XML validation. XML with correct syntax is Well Formed XML.
XML validated against a DTD is Valid XML. A "Well Formed" XML document is a document that conforms to the XML syntax XML DTD (Document Type Definition) A DTD defines the legal elements of an XML document. The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements.
10
XML Schema XML Schema is an XML based alternative to DTD.
The schema is how we assign the data types to each tag and any attributes that are contained in the XML document. A schema is a structured document which must obey XML syntax rules. It is composed of a series of predefined tags and attributes that are part of the XML language and are used to set the data types for the values associated with our custom tags.
11
Schema (cont.) A schema can be part of the XML document or a separate file. Syntax: Schema The Schema tag serves as a container element that delimits the beginning and end of the schema. This tag must be closed and please note the exact spelling with regard to case. xmlns The xmlns attribute is used to declare the schema XML namespace. The value is a URL or URN address that the browser will access to get information on how to parse and validate the code.
12
Schema (cont.) xmlns:dt The xmlns:dt attribute is used to declare the data types of the schema XML namespace. The value is a URL or URN address that the browser will access to get information on the data types to allow code validation. If you are using IE 5 to view your XML document, then you must include the xmlns and the xmlns:dt attributes exactly as displayed below: <Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> ... </Schema>
13
An example with Schema Code for aquarium.xml: <?xml version="1.0"?> <aquarium xmlns="x-schema:aquariumSchema.xml"> <fish>neon tetra</fish> </aquarium> Code for aquariumSchema.xml: <Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <!-- since the fish element contains no elements or attributes --> <!-- we close using the space blackslash --> <ElementType name="fish" content="textOnly" dt:type="string" /> <!-- the aquarium element contains the fish element --> <!-- so we use a closing /ElementType tag --> <ElementType name="aquarium" content="mixed"> <element type="fish" /> </ElementType> </Schema>
14
Displaying an XML Document
The data in an XML document cannot be directly displayed on a browser. Therefore we must apply additional technology to create an HTML page that contains the XML data. We will discuss two ways to do this: 1. Data Binding 2. Style sheets
15
Data Binding Internet Explorer 4 and 5 contain a DSO (Data Source Object) that permits displaying the data in an XML document on an HTML page by using the technology of client-side data binding. This involves: Taking the XML data from the server-side Transferring the data to the client-side Caching the data on the client-side for future access, And binding the data to an HTML tag. The data is treated like a record set in ADO and the data can be manipulated by using the various methods and properties of the ADO Recordset object.
16
Data Binding (cont.) Example: Code for the Xml document
Our goal is to create an HTML page that displays the XML data for the date of birth (dob), name (name), and social security number (ssn) for one staff member at a time. Further, we want to be able to scroll through the list of staff members using navigation buttons and see the data for any staff members.
17
Data Binding (cont.) To accomplish this, we will:
use the src attribute of an inline xml element to link our HTML page to the XML document. use the HTML span tag for the data binding. use the datasrc attribute to link the each span element to the xml element. use the datafld attribute to bind the specified XML data value to the span element. use previous and next input buttons to call data navigation functions. use the MoveNext and MovePrevious ADO methods to navigate our data. use the RecordCount and AbsolutePosition ADO properties to limit our data navigation so that we never go to BOF or EOF.
18
Data Binding (cont.) Source code
<html> <title>Data Binding Example</title> <body> <xml id="xmlStaff" src="devguru_staff_list.xml"> </xml> <b>Use the buttons to scroll up and down the DevGuru Staff List</b> <br><br> NAME: <span datasrc="#xmlStaff" datafld="name"></span> <br> DOB: <span datasrc="#xmlStaff" datafld="dob"></span> <br> SSN: <span datasrc="#xmlStaff" datafld="ssn"></span> <br> <br> <input type="button" value="Previous" onclick="Previous()"> <input type="button" value="Next" onclick="Next()"> <script type="text/javascript"> function Previous() { if(xmlStaff.recordset.AbsolutePosition > 1) xmlStaff.recordset.movePrevious(); } function Next() { if(xmlStaff.recordset.AbsolutePosition < xmlStaff.recordset.RecordCount) xmlStaff.recordset.moveNext(); } </script> </body> </html>
19
Data Binding example (cont.)
Display in IE5
20
Display using style sheets.
Source code for cdCatalog.xml Source code for style sheet The CD Catalog formatted with the CSS file
21
End of XML? NO There certainly is a lot more to XML than what we have discussed. XML data can be embedded directly in an HTML page XML combined with ASP can perform very well to— Manipulate databases. Manipulate the W3C Document object model Dynamically create XML documents from a web page.
22
Why XML? Why mark up the data this way? An XML file is in pure text
any application should be able to use it. Increases data readability significantly. Data transfer is easier E.g. An XML file containing information about books for sale can be transferred to different sections of the pub. Company. Any platform can be made to understand this file, and manipulate it.
23
Why XML (cont.) Gives data some abstraction.
Since the tags themselves carry some meaning, the data is somewhat abstracted here. Displaying mechanisms do not clutter the algorithm. Style sheets (CSS), XSL or data binding can take care of display. Much easier to change the look of the web pages, since the only thing that needs to be changed is the style-sheets.
24
Still not convinced? Go on the web. XML is becoming increasingly a preferred choice over HTML. Check out some discussion boards. Plenty of valid reasons why people prefer XML.
25
Works Cited Beginning Active Server Pages 3.0
Wrox, Pages
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.