SlideShare a Scribd company logo
Session 1 Introduction to XML and Namespace Create by ChungLD faculty XML by Example / Bachkhoa – Aptech Computer Education /34
Objectives Introduction to XML Exploring XML Working with XML XML Syntax XML Namespaces Working with Namespaces Syntax Create by Chungld faculty /34
Overview Markup languages GML  (Generalized Markup Language-1970) describes the document in terms of its format, structure and other properties. SGML (Standard Generalized Markup Language-1980) ensures that the system can represent the data in its own way. HTML (Hyper text Markup Language - 1989) used ASCII text, which allows the user to use any text editor Create by Chungld faculty /34
Evolution of XML  XML is a W3C recommendation The first version (1.0) introduced in 1998 XML is a set of rules for defining semantic tags that break a document into parts and identify the different parts of the document. XML was developed over HTML because of the basic differences between them given in the table below. Create by Chungld faculty /34
Comparison HTML and XML Create by Chungld faculty /34
Features of 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. 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 Create by Chungld faculty /34
Benefits of XML Data Independence Easier to parse Reducing Server Load Easier to create Web site Content Remote Procedure Calls e-Commerce Create by Chungld faculty /34
Example XML Document <?xml version=“1.0” encoding=“iso-8859-1” ?> < FlowerPlanet > < Name > Rose </ Name > < Price > $1 </ Price > < Description > Red   in color </ Description > < Number > 700 </ Number > </ FlowerPlanet > Create by Chungld faculty /34
XML Document Structure Create by Chungld faculty /34
XML document life cycle XML parser creates, manipulates and updates the XML document. It will read the list of records in the XML document and the handler stores it in the form of a data structure. The handler then processes it and displays it in HTML Create by Chungld faculty /34
XML Editors The main functions that editors provide: Add opening and closing tags to the code Check for validity of XML Verify XML against a DTD/Schema Perform series of transforms over a document Color the XML syntax Display the line numbers Present the content and hide the code Complete the word Create by Chungld faculty /34
XML Parsers An XML parser/XML processor reads the document and verifies it for its well-formedness. After the document is verified, the processor converts the document into a tree of elements or a data structure. Commonly used parser are: MSXML Oracle XML Parser Java API for XML Create by Chungld faculty /34
XML Parsers… The two types of parsers are: Non validating parser: It checks the well formedness of the document. Read the document and checks for its conformity with XML standards. Validating parser: It checks the validity of the document using DTD Create by Chungld faculty /34
Browsers After the XML document is read, the parser passes the data structure to the client application. The application can be a web browser. Other programs like database, MIDI program or a spreadsheet program. Commonly used web browsers are: Netscape Mozilla Internet Explorer Firefox Opera Create by Chungld faculty /34
Building an XML document The steps to build an XML document are: Create an XML document in an editor. Save the XML document Load XML document in a browser Create by Chungld faculty /34 Click and see
Exploring the XML document XML version declaration Document Type Definition Document instance in which the content is defined by the markup. Create by Chungld faculty /34 Click and see
Well-formed XML document Well-formness refers to the standards that are to be followed by the XML document. A document is well formed, if it fullfills the following rules: Create by Chungld faculty /34
XML Documents Must Have a Root Element Create by Chungld faculty /34 <root>   <child>     <subchild>.....</subchild>   </child> </root>
XML Tags are Case Sensitive Create by Chungld faculty /34 <Message>This is incorrect</message> <message>This is correct</message>
All XML Elements Must Have a Closing Tag In HTML, you will often see elements that don't have a closing tag: In XML, it is illegal to omit the closing tag. All elements  must  have a closing tag: Create by Chungld faculty /34 <p>This is a paragraph <p>This is another paragraph  <p>This is a paragraph</p> <p>This is another paragraph</p>
XML Elements Must be Properly Nested In HTML, you might see improperly nested elements: In XML, all elements  must  be properly nested within each other: Create by Chungld faculty /34 <b><i>This text is bold and italic</b></i> <b><i>This text is bold and italic</i></b>
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: Create by Chungld faculty /34 <note date=12/11/2007>   <to>Tove</to>   <from>Jani</from> </note> <note date=“12/11/2007”>   <to>Tove</to>   <from>Jani</from> </note>
Entity References Some characters have a special meaning in XML. If you place a character like &quot;<&quot; inside an XML element, it will generate an error because the parser interprets it as the start of a new element. This will generate an XML error: <message>if salary < 1000 then</message>  To avoid this error, replace the &quot;<&quot; character with an  entity reference : <message>if salary &lt; 1000 then</message> Create by Chungld faculty /34
Comments in XML Comments is same HMTL <!-- Comments --> Create by Chungld faculty /34 Click  and see
Processing Instructions Processing instructions are information which is application specific. The instructions do not follow XML rules or internal syntax. With the help of a parser these instructions are passed to the application <?PITarget <instructions>?> Create by Chungld faculty /34
White-space is Preserved in XML HTML truncates multiple white-space characters to one single white-space: HTML: Hello           my name is Tove Output: Hello my name is Tove.  With XML, the white-space in a document is not truncated. Create by Chungld faculty /34
Classification to character data An XML document is divided into markup and character data. Character data describes the document’s actual content with the white space. The text in character data is not processed by the parser and thus not treated as a regular text. Create by Chungld faculty /34 Character data PCDATA CDATA
PCDATA The data that is parsed by the parser is called as parsed character data (PCDATA). The PCDATA specifies that the element has parsed character data. It is used in the element declaration. Example <Semster>X<5&10</Semster> A result it will generate an error as shown: Create by Chungld faculty /34
CDATA The text inside a CDATA section is not parsed by the XML parser. A text is considered in a CDATA section if it contains ‘<‘ or ‘<&>’ character. The  CDATA section cannot be nested. It also does not accept line breaks or spaces inside the <![CDATA[ 0 <X< =10     ]]>  string. Comments are also not recognized. Create by Chungld faculty /34 Click  and see
What is an XML Element? An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can contain other elements, simple text or a mixture of both. Elements can also have attributes. 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  Create by Chungld faculty /34
Example elements <bookstore>   <book category=&quot;CHILDREN&quot;>     <title>Harry Potter</title>     <author>J K. Rowling</author>     <year>2005</year>     <price>29.99</price>   </book>   <book category=&quot;WEB&quot;>     <title>Learning XML</title>     <author>Erik T. Ray</author>     <year>2003</year>     <price>39.95</price>   </book> </bookstore> Create by Chungld faculty /34
XML Attributes XML elements can have attributes in the start tag, just like HTML. Attributes provide additional information about elements. <elementName attName1=“value” attName2=“value”..> Create by Chungld faculty /34 <person sex=&quot;female&quot;>   <firstname>Anna</firstname>   <lastname>Smith</lastname> </person>
XML Validation XML with correct syntax is &quot;Well Formed&quot; XML. XML validated against a DTD is &quot;Valid&quot; XML or XML Schema Create by Chungld faculty /34
Namespaces Duplicate element names Consequences of duplicate element names Create by Chungld faculty /34 <Cd> <Name>…</Name> </Cd> <Singer> <Name>…</Name> </Singer> How do I search for all CD title/names? How do I differentiate between cd name and singer name?
Define Namespaces In XML, elements are distinguished by using namespaces. XML Namspaces provide a globally unique name for an element or attribute so that they do not conflict on another. Create by Chungld faculty /34
Prefixing element names Using prefixes in the element names provide a means for the document authors to prevent name collisions <CD:Title>Feel</CD:Title> and <Book:Title>Returning to Earth</Book:Title> But if the prefixes are not unique, the original problem of duplication would still exist. To solve this problem, each namespace prefix is added to a Uniform Resource Identifier or URI that uniquely identifies the namspace. Create by Chungld faculty /34
Syntax to add namespace URI <elementName xmlns:namespacePrefix=“URI”> You can place attributes in a namespace prefix:localname=“value” Create by Chungld faculty /34 Click  and see
Default namspace A default namespace using the xmlns attribute with a URI as its value. Once this default namespace is declared, child elements that are part of this namespace do not need a namespace prefix. Create by Chungld faculty /34 Click  and see
Override default namespaces The default namespace applies to the element on which it was defined and all descendants of that element. If one of the descendants has another default namespace defined on it, this new namespace definition overrides the previous one and becomes the default for that element and all its descendants. Create by Chungld faculty /34 Click  and see
Refer Website http://www.xmluk.org http://www.zvon.org/xxl/XMLSchemaTutorial/Output/series.html http://www.xmlmaster.org http://xmlwriter.net http://www.w3schools.com/XML/ Create by Chungld faculty /34
Summary and workshop Create by Chungld faculty /34

More Related Content

PPT
XML and DTD
PPT
PDF
SQL Server - Querying and Managing XML Data
PPT
Introduction to XML
PPTX
Basic xml syntax
PPTX
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
PPTX
Basic XML
XML and DTD
SQL Server - Querying and Managing XML Data
Introduction to XML
Basic xml syntax
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Basic XML

What's hot (20)

PDF
XML Introduction
PPT
PPTX
XML | Computer Science
PPT
Lotusphere 2006 AD212 Introduction to DXL
PPTX
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
PPT
Introduction to XML
PPT
O9xml
PPT
Introduction to XML
PPTX
PPTX
Analyzing a Simple DTD
PPT
PPT
Introduction to XML
PDF
Xml tutorial
 
PPT
10. XML in DBMS
XML Introduction
XML | Computer Science
Lotusphere 2006 AD212 Introduction to DXL
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Introduction to XML
O9xml
Introduction to XML
Analyzing a Simple DTD
Introduction to XML
Xml tutorial
 
10. XML in DBMS
Ad

Viewers also liked (7)

PPTX
PPT
Java XML Parsing
PPT
XML.ppt
PPTX
XML, DTD & XSD Overview
PPTX
Introduction to xml
PPTX
Lecture #2 xml
PPTX
Xml ppt
Java XML Parsing
XML.ppt
XML, DTD & XSD Overview
Introduction to xml
Lecture #2 xml
Xml ppt
Ad

Similar to Session 1 (20)

PPT
EXtensible Markup Language
PPTX
Web Development Course - XML by RSOLUTIONS
PPT
Ch2 neworder
PPTX
Introduction to XML
PPTX
XML - Extensible Markup Language for Network Security.pptx
DOCX
XML DTD Validate
PDF
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
PPTX
Intro xml
PDF
xml introduction in web technologies subject
PPTX
Web programming xml
PPT
Xml Presentation-3
PPT
Xml1111
PPT
1 xml fundamentals
PPS
XML - The Extensible Markup Language
PPTX
xml.pptx
PPT
XML Presentation-2
PPT
cis110-xml-xhtml engineering computer science
EXtensible Markup Language
Web Development Course - XML by RSOLUTIONS
Ch2 neworder
Introduction to XML
XML - Extensible Markup Language for Network Security.pptx
XML DTD Validate
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Intro xml
xml introduction in web technologies subject
Web programming xml
Xml Presentation-3
Xml1111
1 xml fundamentals
XML - The Extensible Markup Language
xml.pptx
XML Presentation-2
cis110-xml-xhtml engineering computer science

Recently uploaded (20)

PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
The various Industrial Revolutions .pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
August Patch Tuesday
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Architecture types and enterprise applications.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Assigned Numbers - 2025 - Bluetooth® Document
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A novel scalable deep ensemble learning framework for big data classification...
Enhancing emotion recognition model for a student engagement use case through...
Module 1.ppt Iot fundamentals and Architecture
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Chapter 5: Probability Theory and Statistics
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Group 1 Presentation -Planning and Decision Making .pptx
The various Industrial Revolutions .pptx
DP Operators-handbook-extract for the Mautical Institute
August Patch Tuesday
O2C Customer Invoices to Receipt V15A.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Architecture types and enterprise applications.pdf
TLE Review Electricity (Electricity).pptx
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game

Session 1

  • 1. Session 1 Introduction to XML and Namespace Create by ChungLD faculty XML by Example / Bachkhoa – Aptech Computer Education /34
  • 2. Objectives Introduction to XML Exploring XML Working with XML XML Syntax XML Namespaces Working with Namespaces Syntax Create by Chungld faculty /34
  • 3. Overview Markup languages GML (Generalized Markup Language-1970) describes the document in terms of its format, structure and other properties. SGML (Standard Generalized Markup Language-1980) ensures that the system can represent the data in its own way. HTML (Hyper text Markup Language - 1989) used ASCII text, which allows the user to use any text editor Create by Chungld faculty /34
  • 4. Evolution of XML XML is a W3C recommendation The first version (1.0) introduced in 1998 XML is a set of rules for defining semantic tags that break a document into parts and identify the different parts of the document. XML was developed over HTML because of the basic differences between them given in the table below. Create by Chungld faculty /34
  • 5. Comparison HTML and XML Create by Chungld faculty /34
  • 6. Features of 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. 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 Create by Chungld faculty /34
  • 7. Benefits of XML Data Independence Easier to parse Reducing Server Load Easier to create Web site Content Remote Procedure Calls e-Commerce Create by Chungld faculty /34
  • 8. Example XML Document <?xml version=“1.0” encoding=“iso-8859-1” ?> < FlowerPlanet > < Name > Rose </ Name > < Price > $1 </ Price > < Description > Red in color </ Description > < Number > 700 </ Number > </ FlowerPlanet > Create by Chungld faculty /34
  • 9. XML Document Structure Create by Chungld faculty /34
  • 10. XML document life cycle XML parser creates, manipulates and updates the XML document. It will read the list of records in the XML document and the handler stores it in the form of a data structure. The handler then processes it and displays it in HTML Create by Chungld faculty /34
  • 11. XML Editors The main functions that editors provide: Add opening and closing tags to the code Check for validity of XML Verify XML against a DTD/Schema Perform series of transforms over a document Color the XML syntax Display the line numbers Present the content and hide the code Complete the word Create by Chungld faculty /34
  • 12. XML Parsers An XML parser/XML processor reads the document and verifies it for its well-formedness. After the document is verified, the processor converts the document into a tree of elements or a data structure. Commonly used parser are: MSXML Oracle XML Parser Java API for XML Create by Chungld faculty /34
  • 13. XML Parsers… The two types of parsers are: Non validating parser: It checks the well formedness of the document. Read the document and checks for its conformity with XML standards. Validating parser: It checks the validity of the document using DTD Create by Chungld faculty /34
  • 14. Browsers After the XML document is read, the parser passes the data structure to the client application. The application can be a web browser. Other programs like database, MIDI program or a spreadsheet program. Commonly used web browsers are: Netscape Mozilla Internet Explorer Firefox Opera Create by Chungld faculty /34
  • 15. Building an XML document The steps to build an XML document are: Create an XML document in an editor. Save the XML document Load XML document in a browser Create by Chungld faculty /34 Click and see
  • 16. Exploring the XML document XML version declaration Document Type Definition Document instance in which the content is defined by the markup. Create by Chungld faculty /34 Click and see
  • 17. Well-formed XML document Well-formness refers to the standards that are to be followed by the XML document. A document is well formed, if it fullfills the following rules: Create by Chungld faculty /34
  • 18. XML Documents Must Have a Root Element Create by Chungld faculty /34 <root>   <child>     <subchild>.....</subchild>   </child> </root>
  • 19. XML Tags are Case Sensitive Create by Chungld faculty /34 <Message>This is incorrect</message> <message>This is correct</message>
  • 20. All XML Elements Must Have a Closing Tag In HTML, you will often see elements that don't have a closing tag: In XML, it is illegal to omit the closing tag. All elements must have a closing tag: Create by Chungld faculty /34 <p>This is a paragraph <p>This is another paragraph <p>This is a paragraph</p> <p>This is another paragraph</p>
  • 21. XML Elements Must be Properly Nested In HTML, you might see improperly nested elements: In XML, all elements must be properly nested within each other: Create by Chungld faculty /34 <b><i>This text is bold and italic</b></i> <b><i>This text is bold and italic</i></b>
  • 22. 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: Create by Chungld faculty /34 <note date=12/11/2007>   <to>Tove</to>   <from>Jani</from> </note> <note date=“12/11/2007”>   <to>Tove</to>   <from>Jani</from> </note>
  • 23. Entity References Some characters have a special meaning in XML. If you place a character like &quot;<&quot; inside an XML element, it will generate an error because the parser interprets it as the start of a new element. This will generate an XML error: <message>if salary < 1000 then</message> To avoid this error, replace the &quot;<&quot; character with an entity reference : <message>if salary &lt; 1000 then</message> Create by Chungld faculty /34
  • 24. Comments in XML Comments is same HMTL <!-- Comments --> Create by Chungld faculty /34 Click and see
  • 25. Processing Instructions Processing instructions are information which is application specific. The instructions do not follow XML rules or internal syntax. With the help of a parser these instructions are passed to the application <?PITarget <instructions>?> Create by Chungld faculty /34
  • 26. White-space is Preserved in XML HTML truncates multiple white-space characters to one single white-space: HTML: Hello           my name is Tove Output: Hello my name is Tove. With XML, the white-space in a document is not truncated. Create by Chungld faculty /34
  • 27. Classification to character data An XML document is divided into markup and character data. Character data describes the document’s actual content with the white space. The text in character data is not processed by the parser and thus not treated as a regular text. Create by Chungld faculty /34 Character data PCDATA CDATA
  • 28. PCDATA The data that is parsed by the parser is called as parsed character data (PCDATA). The PCDATA specifies that the element has parsed character data. It is used in the element declaration. Example <Semster>X<5&10</Semster> A result it will generate an error as shown: Create by Chungld faculty /34
  • 29. CDATA The text inside a CDATA section is not parsed by the XML parser. A text is considered in a CDATA section if it contains ‘<‘ or ‘<&>’ character. The CDATA section cannot be nested. It also does not accept line breaks or spaces inside the <![CDATA[ 0 <X< =10   ]]> string. Comments are also not recognized. Create by Chungld faculty /34 Click and see
  • 30. What is an XML Element? An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can contain other elements, simple text or a mixture of both. Elements can also have attributes. 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 Create by Chungld faculty /34
  • 31. Example elements <bookstore>   <book category=&quot;CHILDREN&quot;>     <title>Harry Potter</title>     <author>J K. Rowling</author>     <year>2005</year>     <price>29.99</price>   </book>   <book category=&quot;WEB&quot;>     <title>Learning XML</title>     <author>Erik T. Ray</author>     <year>2003</year>     <price>39.95</price>   </book> </bookstore> Create by Chungld faculty /34
  • 32. XML Attributes XML elements can have attributes in the start tag, just like HTML. Attributes provide additional information about elements. <elementName attName1=“value” attName2=“value”..> Create by Chungld faculty /34 <person sex=&quot;female&quot;>   <firstname>Anna</firstname>   <lastname>Smith</lastname> </person>
  • 33. XML Validation XML with correct syntax is &quot;Well Formed&quot; XML. XML validated against a DTD is &quot;Valid&quot; XML or XML Schema Create by Chungld faculty /34
  • 34. Namespaces Duplicate element names Consequences of duplicate element names Create by Chungld faculty /34 <Cd> <Name>…</Name> </Cd> <Singer> <Name>…</Name> </Singer> How do I search for all CD title/names? How do I differentiate between cd name and singer name?
  • 35. Define Namespaces In XML, elements are distinguished by using namespaces. XML Namspaces provide a globally unique name for an element or attribute so that they do not conflict on another. Create by Chungld faculty /34
  • 36. Prefixing element names Using prefixes in the element names provide a means for the document authors to prevent name collisions <CD:Title>Feel</CD:Title> and <Book:Title>Returning to Earth</Book:Title> But if the prefixes are not unique, the original problem of duplication would still exist. To solve this problem, each namespace prefix is added to a Uniform Resource Identifier or URI that uniquely identifies the namspace. Create by Chungld faculty /34
  • 37. Syntax to add namespace URI <elementName xmlns:namespacePrefix=“URI”> You can place attributes in a namespace prefix:localname=“value” Create by Chungld faculty /34 Click and see
  • 38. Default namspace A default namespace using the xmlns attribute with a URI as its value. Once this default namespace is declared, child elements that are part of this namespace do not need a namespace prefix. Create by Chungld faculty /34 Click and see
  • 39. Override default namespaces The default namespace applies to the element on which it was defined and all descendants of that element. If one of the descendants has another default namespace defined on it, this new namespace definition overrides the previous one and becomes the default for that element and all its descendants. Create by Chungld faculty /34 Click and see
  • 40. Refer Website http://www.xmluk.org http://www.zvon.org/xxl/XMLSchemaTutorial/Output/series.html http://www.xmlmaster.org http://xmlwriter.net http://www.w3schools.com/XML/ Create by Chungld faculty /34
  • 41. Summary and workshop Create by Chungld faculty /34