Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Use of Core XML tags in JSP 
 

Core XML tags provides access to XML data and used to parse these data. There are three tags in this Core XML tag set.

 

Use of Core XML tags in JSP

                          

Example program to show use of Core XML tag in JSP

JSTL (JSP standard tag library) XML tag can be categorized into three sets :

Function Tag name Prefix
Core out, parse, set x
Flow control choose, when, otherwise, forEach, if x
Transformation transform, param x

Core XML Tags:

Core XML tags provides access to XML data and used to parse these data. There are three tags in this Core XML tag set.

1. <x:out> :

This tag is used to evaluate an XPath expression and outputs the result of current variable.

Syntax for <x:out> is shown below:

<x:out select=”XPathExpression” [escapeXml=”{true|false}”]/>

Attributes

select : XPath expression to be evaluated. It's mandatory.
escapeXML: Default value is true. Determine whether characters "<", ">", "&", "'", """ in the resulting string should be converted to their corresponding character entity code.

2. <x:parse> : 

This tag is used to parse an XML document and it saves the resulting object into an EL variable which is specified by the attribute "var"

Syntax is as follows:

<x:parse doc="${xmlFileVariable}" var="variableName" scope="application|request|session" />

3. <x:set> : This tag is used to evaluate an XPath expression and set the result into attribute "var"

Syntax for <x:set> is as follows :

<x:set select=”XPathExpression” var="variableName" />

To use XML tags in your program you have to firstly download these jar files in your Tomcat's "lib" folder. These jar files are:

  1. jstl.jar 
  2. resolver.jar
  3. serializer.jar
  4. standard.jar
  5. xercesImpl.jar
  6. xercesSamples.jar
  7. xml-apis.jar
  8. xalan.jar

Visit this link to download these jar files: http://www.mail-archive.com/taglibs-user@jakarta.apache.org/msg08807.html

This example illustrates use of XML core tags into a JSP file to show parsed data of an XML file "user.xml".

1. user.xml

<?xml version="1.0"?>
  <user>
       <information>
           <fname>amit</fname>
           <mname>kumar</mname>
           <lname>raghuwanshi</lname>
           <age>21</age>
       </information>
       <information>
           <fname>sandeep</fname>
           <mname>kumar</mname>
           <lname>suman</lname>
           <age>23</age>
        </information>
   </user>

This user.xml data is being parsed and is shown in JSP file by using <x:parse> and <x:out> and one flow control tag <x:forEach>. To have use of these XML tags you have to include following code in your JSP file.

<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>

One core JSTL is also used in this JSP file to import user.xml file into JSP file variable by var attribute of <c:import>. This core JSTL tag library can be used by using code:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

Full code for this JSP file is given as below:

2. XMLinJSP.jsp

<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head><title>Use of Core XML tags</title></head>
<body>
<h2>Example of using Core XML tags</h2>
 <c:import url="http://localhost:8080/Example/user.xml" var="user" />
    <x:parse xml="${user}" var="doc" /> 
        <h3>Information of user.xml file</h3>
          <x:forEach select="$doc/user/information" var="n">
              First Name:<x:out select="$n/fname"/><br>
              Middle Name:<x:out select="$n/mname"/><br>
              Last Name:<x:out select="$n/lname"/><br>
             Age: <x:out select="$n/age"/><br>
          </x:forEach>
</body>
</html>

To execute this example follow these steps :

  • Create and save an XML file user.xml
  • Download and put all jar files (as given above) into lib folder
  • Create and save XMLinJSP.jsp
  • Start Tomcat web server and type following url
    http://localhost:8080/Example/XMLinJSP.jsp

Output:

user.xml file data would show like this:

and output of JSP file would be

Download Source code

                          

» View all related tutorials
Related Tags: java c string jsp ide class strings script object io objects method get char ip using sequence id declaration length

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.