JSTL XML x:parse Tag

The <x: parse> tag is used to parse the xml content and the result will be stored in specified variable.

Syntax Of <x: parse> Tag

<x: parse attributes> body content </x: parse>

Attributes Of <x: parse> Tag

docSpecifies that source XML document to be parsed.
systemIdSpecifies the system identifier in xml document for parsing.
filterFilter object is been used in xml document to filter the document.
varIt specifies the variable name which stores parse xml document.
scopeThe Scope into which the variable attribute has to be set.
varDomSpecifies the variable name of the parsed xml document has to be set.
scopeDomSpecifies the scope of varDom attribute has to be set.


Listing 1: xParse.xml file





Listing 2: example.jsp file

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

  <title> x:parse Tags</title>

<h3>Fruits Information:</h3>

<c:import var="fruitinfo" url="xParse.xml"/>

<x:parse xml="${fruitinfo}" var="output"/>

<b>Name of the Fruit is</b>:

<x:out select="$output/fruits/fruit[1]/name" /><br>

<b>The price of the Apple</b>:

<x:out select="$output/fruits/fruit[3]/price" />


Details of the Code

  • <c:import var=”fruitinfo” url=”xParse.xml”/> tag is used to include the content of another resource in the current JSP.
  • <x:parse xml=”${fruitinfo}” var=”output”/> tag is used to parse the xml content and the result is been stored in specified variable.
  • <x:out select=”$output/fruits/fruit[1]/name” /> tag is used to display the particular fruit name in the output.
  • <x:out select=”$output/fruits/fruit[3]/price” /> tag is used to display the price of the particular fruit which we want.

Steps for Execution

Before executing the xml programs we should add jar files in eclipse namely:


  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server


When the execution process is completed successfully we will get the following output :

x parse tag output

Previous Tutorial :  JSTL XML x:set Tag :: Next Tutorial : JSTL XML x:transform Tag

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!