SlideShare a Scribd company logo
XML Basics Training Arshi Arora
Agenda What is XML XML Naming Rules Displaying XML Files with CSS XML Namespaces Character Data-CDATA Parsed Character Data-PCDATA Well Formed XML Documents
What is XML? XML stands for E X tensible  M arkup  L anguage  . 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
An Example   <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
XML Declaration   The XML declaration in the document map consists of the following:    The version number,  <?xml version=&quot;1.0&quot;?> .  This is mandatory. Although the number will  change for future versions of XML, 1.0 is the  current version.    The encoding declaration,  <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;? >   This is optional. If used, the encoding declaration must appear immediately after the version I information in the XML declaration, and must contain a value representing an existing character encoding.
An XML declaration may also contain a standalone declaration, for example,  <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> Like the encoding declaration, the standalone declaration is optional. If used, the standalone declaration must appear last in the XML declaration.
Encoding Declaration   The encoding declaration identifies which encoding is used to represent the characters in the document. Although XML parsers can determine automatically if a document uses the UTF-8 or UTF-16 Unicode encoding, this declaration should be used in documents that support other encodings. For example, the following is the encoding declaration for a document that uses the  ISO-8859-1  (Latin 1). <?xml version=&quot;1.0&quot;  encoding =&quot; ISO-8859-1 &quot;?>     Case in the value specified is not considered by the encoding declaration.  &quot;ISO-8859-1&quot;  is the equivalent of  &quot;iso-8859-1&quot; . The following is the encoding declaration for a document that uses the Japanese encoding method Shift-JIS. <?xml version=&quot;1.0&quot; encoding=&quot;Shift-JIS&quot;?>
Standalone Declaration   The standalone declaration indicates whether a document relies on information from an external source, such as external document type definition (DTD), for its content. If the standalone declaration has a value of  &quot;yes&quot; , for example,  <?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?> , the parser will report an error if the document references an external DTD or external entities.
XML Naming Rules   XML elements must follow these naming rules: Names can contain letters, numbers, and other characters Names must not start with a number or punctuation character Names must not start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces
Some important points XML Document forms a tree structure All XML Elements must have a closing Tag XML Tags are case sensitive XML Elements must be properly nested XML Documents Must Have a Root Element   XML Attribute Values Must be Quoted
  Attributes in xml   <gangster name='George &quot;Shotgun&quot; Ziegler'>     <gangster name=&quot;George &quot;Shotgun&quot; Ziegler&quot;>    
Displaying XML Files with CSS   XML File <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <?xml-stylesheet type=&quot;text/css&quot; href=&quot;cd_catalog.css&quot;?> <CATALOG>  <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <YEAR>1988</YEAR> </CD> </CATALOG>
CSS file CATALOG { background-color: #ffffff; width: 100%; } CD {display: block; margin-bottom: 30pt; margin-left: 0; } TITLE {color: #FF0000; font-size: 20pt; } ARTIST {color: #0000FF; font-size: 20pt; } YEAR { display: block; color: #000000; margin-left: 20pt; }
Name Conflicts In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications. Solving the Name Conflict Using a Prefix   Name conflicts in XML can easily be avoided using a name prefix. <h:table>  <h:tr> <h:td>Apples</h:td>  <h:td>Bananas</h:td> </h:tr> </h:table> <f:table>  <f:name>African Coffee Table</f:name>  <f:width>80</f:width>  <f:length>120</f:length> </f:table>
XML Namespaces - The xmlns Attribute   When using prefixes in XML, a so-called  namespace  for the prefix must be defined. The namespace is defined by the  xmlns attribute  in the start tag of an element. The namespace declaration has the following syntax. xmlns: prefix =&quot; URI &quot;.
Namespace Example   <root>   <h:table xmlns:h=&quot;http://www.w3.org/TR/html4/&quot;>   <h:tr>   <h:td>Apples</h:td>   <h:td>Bananas</h:td>   </h:tr>   </h:table>   <f:table xmlns:f=&quot;http://www.w3schools.com/furniture&quot;>   <f:name>African Coffee Table</f:name>   <f:width>80</f:width>   <f:length>120</f:length>   </f:table>   </root>
CDATA - (Unparsed) Character Data   The term CDATA is used about text data that should not be parsed by the XML parser.  Characters like &quot;<&quot; and &quot;&&quot; are illegal in XML elements. &quot;<&quot; will generate an error because the parser interprets it as the start of a new element. &quot;&&quot; will generate an error because the parser interprets it as the start of an character entity. Some text, like JavaScript code, contains a lot of &quot;<&quot; or &quot;&&quot; characters. To avoid errors script code can be defined as CDATA. Everything inside a CDATA section is ignored by the parser. A CDATA section starts with &quot; <![CDATA[ &quot; and ends with &quot; ]]> &quot;: A CDATA section cannot contain the string &quot;]]>&quot;. Nested CDATA sections are not allowed. The &quot;]]>&quot; that marks the end of the CDATA section cannot contain spaces or line breaks.
Example <script>   <![CDATA[   function matchwo(a,b)   {   if (a < b && a < 0) then   {   return 1;   }   else  {   return 0;   } } ]]> </script>
PCDATA - Parsed Character Data   XML parsers normally parse all the text in an XML document. When an XML element is parsed, the text between the XML tags is also parsed.   The parser does this because XML elements can contain other elements
Well Formed XML Documents   A &quot;Well Formed&quot; XML document has correct XML syntax. The syntax rules were described in the previous chapters  : XML documents must have a root element  XML elements must have a closing tag  XML tags are case sensitive  XML elements must be properly nested  XML attribute values must be quoted
Valid XML Documents A &quot;Valid&quot; XML document is a &quot;Well Formed&quot; XML document, which also conforms to the rules of a Document Type Definition (DTD)
Thanks

More Related Content

PPT
PPTX
DTD
PPT
XML Schema
PDF
Introduction to DTD
PPTX
Xml dtd
PPT
4 xml namespaces and xml schema
PPTX
XML, DTD & XSD Overview
PPTX
XML's validation - XML Schema
DTD
XML Schema
Introduction to DTD
Xml dtd
4 xml namespaces and xml schema
XML, DTD & XSD Overview
XML's validation - XML Schema

What's hot (20)

PPTX
35 schemas
PDF
IQPC Canada XML 2001: How to develop Syntax and XML Schema
PPTX
Introduction to xml
PPT
3 xml namespaces and xml schema
PPT
2 dtd - validating xml documents
PPT
XML and DTD
PPT
PPTX
Unit iv xml
PPT
Introduction to XML
PPTX
Regular expression unit2
PPT
00 introduction
PPTX
XML DTD and Schema
PPTX
Introduction to XML
PPTX
PPT
5 xsl (formatting xml documents)
PPTX
fundamentals of XML
35 schemas
IQPC Canada XML 2001: How to develop Syntax and XML Schema
Introduction to xml
3 xml namespaces and xml schema
2 dtd - validating xml documents
XML and DTD
Unit iv xml
Introduction to XML
Regular expression unit2
00 introduction
XML DTD and Schema
Introduction to XML
5 xsl (formatting xml documents)
fundamentals of XML
Ad

Similar to Xml (20)

PPT
PPT
PPT
O9xml
PPT
PPT
Ch2 neworder
PPTX
WEB PROGRAMMING
PPTX
Unit3wt
PPTX
Unit3wt
PPTX
PPT
eXtensible Markup Language (By Dr.Hatem Mohamed)
PPTX
Introduce to XML
PPT
Introduction To Xml
PPT
Introduction to XML
PPTX
Xml andweb services
PDF
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
PPT
Web Services Part 1
PPT
Extensible Markup Language - XML || Presentation
PPTX
xml.pptx
PPTX
Unit 5 xml (1)
O9xml
Ch2 neworder
WEB PROGRAMMING
Unit3wt
Unit3wt
eXtensible Markup Language (By Dr.Hatem Mohamed)
Introduce to XML
Introduction To Xml
Introduction to XML
Xml andweb services
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Web Services Part 1
Extensible Markup Language - XML || Presentation
xml.pptx
Unit 5 xml (1)
Ad

Xml

  • 1. XML Basics Training Arshi Arora
  • 2. Agenda What is XML XML Naming Rules Displaying XML Files with CSS XML Namespaces Character Data-CDATA Parsed Character Data-PCDATA Well Formed XML Documents
  • 3. What is XML? XML stands for E X tensible M arkup L anguage . 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
  • 4. An Example   <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 5. XML Declaration The XML declaration in the document map consists of the following:   The version number, <?xml version=&quot;1.0&quot;?> . This is mandatory. Although the number will change for future versions of XML, 1.0 is the current version.   The encoding declaration, <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;? > This is optional. If used, the encoding declaration must appear immediately after the version I information in the XML declaration, and must contain a value representing an existing character encoding.
  • 6. An XML declaration may also contain a standalone declaration, for example, <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> Like the encoding declaration, the standalone declaration is optional. If used, the standalone declaration must appear last in the XML declaration.
  • 7. Encoding Declaration The encoding declaration identifies which encoding is used to represent the characters in the document. Although XML parsers can determine automatically if a document uses the UTF-8 or UTF-16 Unicode encoding, this declaration should be used in documents that support other encodings. For example, the following is the encoding declaration for a document that uses the ISO-8859-1 (Latin 1). <?xml version=&quot;1.0&quot; encoding =&quot; ISO-8859-1 &quot;?>   Case in the value specified is not considered by the encoding declaration. &quot;ISO-8859-1&quot; is the equivalent of &quot;iso-8859-1&quot; . The following is the encoding declaration for a document that uses the Japanese encoding method Shift-JIS. <?xml version=&quot;1.0&quot; encoding=&quot;Shift-JIS&quot;?>
  • 8. Standalone Declaration The standalone declaration indicates whether a document relies on information from an external source, such as external document type definition (DTD), for its content. If the standalone declaration has a value of &quot;yes&quot; , for example, <?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?> , the parser will report an error if the document references an external DTD or external entities.
  • 9. XML Naming Rules XML elements must follow these naming rules: Names can contain letters, numbers, and other characters Names must not start with a number or punctuation character Names must not start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces
  • 10. Some important points XML Document forms a tree structure All XML Elements must have a closing Tag XML Tags are case sensitive XML Elements must be properly nested XML Documents Must Have a Root Element XML Attribute Values Must be Quoted
  • 11.   Attributes in xml <gangster name='George &quot;Shotgun&quot; Ziegler'>   <gangster name=&quot;George &quot;Shotgun&quot; Ziegler&quot;>  
  • 12. Displaying XML Files with CSS XML File <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <?xml-stylesheet type=&quot;text/css&quot; href=&quot;cd_catalog.css&quot;?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <YEAR>1988</YEAR> </CD> </CATALOG>
  • 13. CSS file CATALOG { background-color: #ffffff; width: 100%; } CD {display: block; margin-bottom: 30pt; margin-left: 0; } TITLE {color: #FF0000; font-size: 20pt; } ARTIST {color: #0000FF; font-size: 20pt; } YEAR { display: block; color: #000000; margin-left: 20pt; }
  • 14. Name Conflicts In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications. Solving the Name Conflict Using a Prefix Name conflicts in XML can easily be avoided using a name prefix. <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table>
  • 15. XML Namespaces - The xmlns Attribute When using prefixes in XML, a so-called namespace for the prefix must be defined. The namespace is defined by the xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns: prefix =&quot; URI &quot;.
  • 16. Namespace Example <root> <h:table xmlns:h=&quot;http://www.w3.org/TR/html4/&quot;> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table xmlns:f=&quot;http://www.w3schools.com/furniture&quot;> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root>
  • 17. CDATA - (Unparsed) Character Data The term CDATA is used about text data that should not be parsed by the XML parser. Characters like &quot;<&quot; and &quot;&&quot; are illegal in XML elements. &quot;<&quot; will generate an error because the parser interprets it as the start of a new element. &quot;&&quot; will generate an error because the parser interprets it as the start of an character entity. Some text, like JavaScript code, contains a lot of &quot;<&quot; or &quot;&&quot; characters. To avoid errors script code can be defined as CDATA. Everything inside a CDATA section is ignored by the parser. A CDATA section starts with &quot; <![CDATA[ &quot; and ends with &quot; ]]> &quot;: A CDATA section cannot contain the string &quot;]]>&quot;. Nested CDATA sections are not allowed. The &quot;]]>&quot; that marks the end of the CDATA section cannot contain spaces or line breaks.
  • 18. Example <script> <![CDATA[ function matchwo(a,b) { if (a < b && a < 0) then { return 1; } else { return 0; } } ]]> </script>
  • 19. PCDATA - Parsed Character Data XML parsers normally parse all the text in an XML document. When an XML element is parsed, the text between the XML tags is also parsed.   The parser does this because XML elements can contain other elements
  • 20. Well Formed XML Documents A &quot;Well Formed&quot; XML document has correct XML syntax. The syntax rules were described in the previous chapters : XML documents must have a root element XML elements must have a closing tag XML tags are case sensitive XML elements must be properly nested XML attribute values must be quoted
  • 21. Valid XML Documents A &quot;Valid&quot; XML document is a &quot;Well Formed&quot; XML document, which also conforms to the rules of a Document Type Definition (DTD)