JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

JSTL XML x:parse Tag

February 27, 2014 by Krishna Srinivasan Leave a Comment

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

[code lang=”html”]
<x: parse attributes> body content </x: parse>
[/code]

Attributes Of <x: parse> Tag

Attributes Description
doc Specifies that source XML document to be parsed.
systemId Specifies the system identifier in xml document for parsing.
filter Filter object is been used in xml document to filter the document.
var It specifies the variable name which stores parse xml document.
scope The Scope into which the variable attribute has to be set.
varDom Specifies the variable name of the parsed xml document has to be set.
scopeDom Specifies the scope of varDom attribute has to be set.

Example

Listing 1: xParse.xml file

[code lang=”html”]
<fruits>
<fruit>
<name>Grapes</name>
<price>40/kg</price>
</fruit>

<fruit>
<name>Orange</name>
<price>30/kg</price>
</fruit>

<fruit>
<name>Apple</name>
<price>90/kg</price>
</fruit>

</fruits>
[/code]

Listing 2: example.jsp file

[code lang=”html”]
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

<html>
<head>
<title> x:parse Tags</title>
</head>
<body>

<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" />

</body>
</html>
[/code]

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:
xalan-2.7.0.jar

<

  • 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

Output

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

Filed Under: Java EE Tagged With: JSTL Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved