Global GuideLine Home HTML Tutorial JavaScript Tutorial SQL Tutorial CSS Tutorial SEO Tutorial XML Tutorial XSLT Tutorial Articles Tutorial Interview Questions and Answers Guide Jobs GuideLine Bookmark With Google Bookmark With Yahoo Bookmark With FaceBook Bookmark With Live Follow @GlobalGuideLine on Twitter Bookmark Global GuideLine
XML CDATA, XML Tutorial, Global Guideline

Bookmark this webpage. Bookmark: XML CDATA, XML Tutorial Global Guideline is UNITED STATES's favorite website


      Home                    

Basic XML Guide.       
 XML Introduction.       
 XML Tags Guide.       
 XML Attributes.           
 XML Syntax Guide.    
 XML Compilation.      
 XML Execution.          
 XML with CSS.           
 XML with XSL.            
 XML Data Island.        
 XML Professional.       
 XML with JavaScript. 
 XML Namespaces.      
 XML CDATA.
 XML Editors.               
 XML Summary.           

XML Tutorial >> XML CDATA.


     Back             Next     



In XML to read and update, create and manipulate an XML document, we will need an XML parser that will parse or validate all the XML document with standards of W3C.  The parser loads the document into our computer's memory and when the document is loaded, its data can be manipulated using the DOM Document Object Model. The DOM treats the XML document as a tree that's why we can see an XML document in web browser as a tree.

Now the only content inside a CDATA section of XML document will be ignored by the XML parser.  So when the parser parse the XML tags then it will also parse the content or text in between tags are also parsed by it.  As shown in example below.

XML for CDATA Example

<employee>
<firstName>Creston</firstName>
<lastName>Narvon</lastName>
<gender>m</gender>
<DOB>22/04/1976</DOB>
</employee>

On above XML code all the tags like <employee> <firstName> <lastName> <gender> and <DOB> will be parse by the XML parser and its content like Creston, Narvon, m and 22/04/1976 will also be parse by the XML parser.  Parser observe the tags and match them with XML standards. Like <firstName> is embeded in <employee> root tag and that's why in web browser we can see it as tree.

XML Parser Issues.

Some character are illegal in XML to use them like "<" less then sign and " quotes and grater then ">" sign & and sign, single quote ' or Apostrophes.  As we use the less then < sign in below example, it is not a valid XML document and it will be appear having an error in browser.

Invalid XML CDATA

<employee>;
   <firstName>"Creston"</firstName>
   <salary>salary is < 3100 </salary>
</employee>

On above example of invalid XML we can see we use " around the Creston and it is not a valid way to define content of XML tags. and in [Salary is < 3100] we used < sign it is also not allowed.  In  two character  are < and & sign are strictly illegal so when ever we will use these parser will not allow.  Solution for this is, we will use XML CDATA as an XML section and here we can use the < and & sign and others like > double quotes " and single quotes '.  

Valid XML CDATA Example

<script>
<![CDATA[
function checksalary(salary)
{
if (salary < 3100) than
   {
     return true
   }
else 
   {
     return false
   }
}
]]>
</script>

As we tried to used < sign on the example at the top of page of this section of XML Tutorial and XML parser generate the error now on above example we can use these characters as shown and parser will ignore them all.
Between the start of the section, "<![CDATA[" and the end of the section, "]]>", all character data is passed directly to the application. The only string that cannot occur in a CDATA section is "]]>". Comments are not recognized in a CDATA section. If present, the literal text "<!--comment-->" will be passed directly to the application. The character string ]]> is not allowed within a CDATA block as it would signal the end of the CDATA block. CDATA does not work in HTML.


     Back             Next     
 
In order to link this page as Reference, click on below text area and pres (CTRL-C) to copy the code in clipboard or pres right click then copy the following lines after that past into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code:

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright © 2005-2006 www.globalguideline.com All rights reserved. Join Global Guide Line community. 440 visitors are online now