Download presentation
Published byLynn Phelps Modified over 9 years ago
1
Introduction to XML History of XML Advantages of XML
Syntax and structure of XML Rules of well formed XML document Components of XML XML Basics
2
Content History of XML Advantages of XML Syntax and structure of XML
Rules of well formed XML document Components of XML
3
History of XML Emerged as a way of its predecessors SGML and HTML
Standard Generalised Markup Language is an extensible tool for semantic markup but pretty dam and complex HTML was free and simple but used only regular people
4
History of XML In 1996 there was a discussion about to find a extensiblity of SGML and simplicity of HTML W3C decide to sponsor a new markup language Finally in 1998 W3C approved the Version 1.0 of XML specification
5
What is XML 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
6
Difference between HTML and XML
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. XML is about carrying information HTML is about displaying information
7
XML Naming Rules XML elements must follow these 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, no words are reserved.
8
XML and Structured Data
Pre-XML representation of data: XML representation of the same data: “PO-1234”,”CUST001”,”X9876”,”5”,”14.98” <PURCHASE_ORDER> <PO_NUM> PO-1234 </PO_NUM> <CUST_ID> CUST001 </CUST_ID> <ITEM_NUM> X9876 </ITEM_NUM> <QUANTITY> 5 </QUANTITY> <PRICE> </PRICE> </PURCHASE_ORDER>
9
Advantages of XML The programmer are not restricted to use the limited set of tags With XML the programmer can create own tags Each organization can build a library of tags HTML consists of dozens of pre-defined tags but XML is a tool used to generates markup language
10
Syntax and Structure Components of an XML Document
<?xml version=“1.0” ?> <?xml-stylesheet type="text/xsl" href=“template.xsl"?> <ROOT> <ELEMENT1><SUBELEMENT1 /><SUBELEMENT2 /></ELEMENT1> <ELEMENT2> </ELEMENT2> <ELEMENT3 type=‘string’> </ELEMENT3> <ELEMENT4 type=‘integer’ value=‘9.3’> </ELEMENT4> </ROOT> Elements with Attributes Elements Prologue (processing instructions)
11
Syntax and Structure Rules For Well-Formed XML
There must be one, and only one, root element Sub-elements must be properly nested A tag must end within the tag in which it was started Attributes are optional Defined by an optional schema
12
Attribute values must be enclosed in “” or ‘’
Processing instructions are optional XML is case-sensitive <tag> and <TAG> are not the same type of element
13
Syntax and Structure Well-Formed XML?
No, CHILD2 and CHILD3 do not nest propertly <xml? Version=“1.0” ?> <PARENT> <CHILD1>This is element 1</CHILD1> <CHILD2><CHILD3>Number 3</CHILD2></CHILD3> </PARENT>
14
Syntax and Structure Well-Formed XML?
No, there are two root elements <xml? Version=“1.0” ?> <PARENT> <CHILD1>This is element 1</CHILD1> </PARENT> <CHILD1>This is another element 1</CHILD1>
15
Syntax and Structure Well-Formed XML?
Yes <xml? Version=“1.0” ?> <PARENT> <CHILD1>This is element 1</CHILD1> <CHILD2/> <CHILD3></CHILD3> </PARENT>
16
Components of XML XML declaration (or) Processing instructions
Elements and Sub elements Elements with attributes
17
XML declarations Suggested by W3C specification
It is a processing instruction The processing instruction notifies the processing agent that the following document has been marked up as XML doc <?xml version = "1.0"?>
18
XML declaration All XML declaration or processing instruction should begin with <? and ?> Following the <? You will find the name of processing instruction which in this case is “xml”
19
Attributes of XML declaration
The XML processing instruction requires that you to specify a version attribute The others are optional attribute Standalone encoding
20
Attributes of the XML declaration
Version The Version attribute allows you to specify the current version of XML which is 1.0 Standalone The standalone attribute specifies whether the document has any markup declarations that are defined in a separate document
21
Attributes of the XML declaration
Encode All XML parsers must support 8-bit and 16-bit Unicode encoding
22
<NAME>Frank Lee</NAME>
Elements Once declaring the processing instruction we need to start code the XML document Elements are the basic units of XML content Every element consists of a start tag and an end tag <NAME>Frank Lee</NAME>
23
The root element, also often called the document tag,
All XML documents must have at least one root element to be well formed. The root element, also often called the document tag,
24
Sample XML file <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <DOCUMENT> <CONTACT> <NAME>Gunther Birznieks</NAME> <PHONE> </PHONE> </CONTACT> <NAME>Susan Czigany</NAME> <PHONE> </PHONE> </DOCUMENT>
25
XML’s hidden role in .NET
XML use is ubiquitous throughout .NET Web Services & XML Based on XML standards: SOAP, WSDL, UDDI, … XML in Configuration files Application information stored in XML-based configuration files
26
XML’s hidden role in .NET
XML&ADO.NET Data Access Provides conversion between DataSets and XML DataSets are serialized as XML
27
Web Services & XML Web Services are a very general model for building applications and can be implemented for any operation system that supports communication over the Internet. The web services are initially created with the help of a XML file
28
XML in Configuration files
ASP.NET stores the settings in human readable format using the configuration files such as machine.config and web.config Here XML provides an all-purpose languages that is designed to let programmers to store data in customized and standardized way of using tags
29
XML&ADO.NET Data Access
The internal format of the ADO.NET component use to store the data is actually in XML Normally with ADO components the data is exchanged in the binary format,which has difficulty in crossing the boundaries
30
XML &ADO.NET Data Access
With ADO.NET components exchange pure XML which can flow over normal channels This XML format is extensible over to different operating system and non-Microsoft development language
31
NET XML Framework • Microsoft's.NET introduces a new suite of XML APIs
– Built on industry standards XML 1.0, Namespaces, DOM L2, XPath 1.0, XSLT 1.0, XSD, SOAP, WSDL, UDDI Commonly referred to as the .NET XML stack
32
.NET XML Namespaces .NET XML stack is partitioned over several namespaces – System.Xml – System.Xml.XPath – System.Xml.Xsl – System.Xml.Schema – System.Xml.Serialization
33
Attributes Attributes are used to add extra information to an element
Instead of using a sub tag we can use the an attribute <?xml version=“1.0”?> <Supermarket> <Product id=“1” Name=“Chair”> <Price=“45.60”> </Product>
34
Using Attributes and Values
Attributes in XML are more stringent Attributes must always have values Attribute values must be enclosed with double quotes Eg <Product name=“Chair”/> Acceptable <Product name=chair/ Not Acceptable <Product name /> Not Acceptable
35
Adding comments Comments are bracketed by the codes
<!– This is test file --> <?xml version="1.0"?> <Supermarket> <!-- This is test file --> <Product ID="1" Name="Chair> <Price ="45.67"> </Product> <!-- This to test end --> </Supermarket>
36
XML Syntax rule -I All XML Elements must Have a Closing Tag
<p>This is a paragraph</p> <p>This is another paragraph</p>
37
XML Syntax rule-II XML Tags are Case Sensitive
With XML, the tag <Letter> is different from the tag <letter>. <Message>This is incorrect</message> <message>This is correct</message>
38
<b><i>This text is bold and italic</i></b>
XML Syntax rule-III XML Elements Must be Properly Nested Properly nested" simply means that since the <i> element is opened inside the <b> element, it must be closed inside the <b> element. <b><i>This text is bold and italic</i></b>
39
XML Syntax rule-IV XML Documents Must Have a Root Element
XML documents must contain one element that is the parent of all other elements. This element is called the root element. <root> <child> <subchild>....</subchild> </child> </root>
40
XML Syntax rule-V XML Attribute Values Must be Quoted
In XML the attribute value must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct: <note date=12/11/2007> <to>Tove</to> <from>Jani</from> </note> <note date= “12/11/2007”> <to>Tove</to> <from>Jani</from> </note>
41
XML Tree
42
<message>if salary < 1000 then</message>
XML Syntax rule-VI Entity References Some characters have a special meaning in XML. If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. <message>if salary < 1000 then</message>
43
<message>if salary < 1000 then</message>
XML Syntax rule-VII To avoid this error, replace the "<" character with an entity reference Replace the “<“ character with an entity reference <message>if salary < 1000 then</message>
44
XML Syntax rule-VIII There are 5 predefined entity references in XML:
< less than > greater than & & Ampersand ' ‘ apostrophe " “ Quotation mark
45
Entities <message>if salary < 1000 then</message>
46
XML Syntax rule-IX Comments in XML
The syntax for writing comments in XML is similar to that of HTML. <!-- This is a comment -->
47
XML Syntax rules-X With XML, White Space is Preserved
HTML reduces multiple white space characters to a single white space With XML, the white space in your document is not truncated. HTML: Hello my name is Tove Output: Hello my name is Tove.
48
XML Namespaces - The xmlns Attribute
The namespace is defined by the xmlns attribute in the start tag of an element The namespace declaration has the following syntax. xmlns:prefix="URI". <h:table xmlns:h="
49
<root> <h:table xmlns:h=" <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> In the example above, the xmlns attribute in the <table> tag give the h: and prefixes a qualified namespace. companies use the namespace as a pointer to a web page containing namespace information.
50
Uniform Resource Identifier
A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource. The most common URI is the Uniform Resource Locator (URL) which identifies an Internet domain address
51
Syntax and Structure Namespaces: Overview
Part of XML’s extensibility Allow authors to differentiate between tags of the same name (using a prefix) Frees author to focus on the data and decide how to best describe it Allows multiple XML documents from multiple authors to be merged URLs and URNs for namespaces do not have to be “live” – they only need to be unique strings.
52
Identified by a URI (Uniform Resource Identifier)
When a URL is used, it does NOT have to represent a live server
53
Syntax and Structure Namespaces: Declaration
Namespace declaration examples: xmlns: bk = “ xmlns: bk = “urn:mybookstuff.org:bookinfo” xmlns: bk = “ Namespace declaration Prefix URI (URL)
54
Syntax and Structure Namespaces: Default Namespace
An XML namespace declared without a prefix becomes the default namespace for all sub-elements All elements without a prefix will belong to the default namespace: <BOOK xmlns=“ <TITLE>All About XML</TITLE> <AUTHOR>Joe Developer</AUTHOR>
55
Default Namespace Defining a default namespace for an element saves us from using prefixes in all the child elements. <table xmlns=" <tr> <td>Apples</td> <td>Bananas</td> </tr> </table>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.