- JSP - Home
- JSP - Overview
- JSP - Environment Setup
- JSP - Architecture
- JSP - Lifecycle
- JSP - Syntax
- JSP - Directives
- JSP - Actions
- JSP - Implicit Objects
- JSP - Client Request
- JSP - Server Response
- JSP - Http Status Codes
- JSP - Form Processing
- JSP - Writing Filters
- JSP - Cookies Handling
- JSP - Session Tracking
- JSP - File Uploading
- JSP - Handling Date
- JSP - Page Redirect
- JSP - Hits Counter
- JSP - Auto Refresh
- JSP - Sending Email
- JSP - Standard Tag Library
- JSP - Database Access
- JSP - XML Data
- JSP - Java Beans
- JSP - Custom Tags
- JSP - Expression Language
- JSP - Exception Handling
- JSP - Debugging
- JSP - Security
- JSP - Internationalization
- JSP Useful Resources
- JSP - Questions and Answers
- JSP - Quick Guide
- JSP - Useful Resources
- JSP - Discussion
JSTL - XML <x:parse> Tag
The <x:parse> tag is used to parse the XML data specified either via an attribute or in the tag body.
Attribute
The <x:parse> tag has the following attributes −
| Attribute | Description | Required | Default |
|---|---|---|---|
| var | A variable that contains the parsed XML data | No | None |
| xml | Text of the document to parse (String or Reader) | No | Body |
| systemId | The system identifier URI for parsing the document | No | None |
| filter | The filter to be applied to the source document | No | None |
| doc | XML document to be parsed | No | Page |
| scope | Scope of the variable specified in the var attribute | No | Page |
| varDom | A variable that contains the parsed XML data | No | Page |
| scopeDom | Scope of the variable specified in the varDom attribute | No | Page |
Example
The following example shows how parse can be used to read the external XML file −
We have seen how we can parse XML from the body of the given document. Let us now put following content in the books.xml file −
<books>
<book>
<name>Padam History</name>
<author>ZARA</author>
<price>100</price>
</book>
<book>
<name>Great Mistry</name>
<author>NUHA</author>
<price>2000</price>
</book>
</books>
Now try the following main.jsp, keeping in the same directory −
<%@ 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>JSTL x:parse Tags</title>
</head>
<body>
<h3>Books Info:</h3>
<c:import var = "bookInfo" url = "http://localhost:8080/books.xml"/>
<x:parse xml = "${bookInfo}" var = "output"/>
<b>The title of the first book is</b>:
<x:out select = "$output/books/book[1]/name" />
<br>
<b>The price of the second book</b>:
<x:out select = "$output/books/book[2]/price" />
</body>
</html>
Access the above JSP using http://localhost:8080/main.jsp, the following result will be displayed −
Books Info:
The title of the first book is:Padam History
The price of the second book: 2000
jsp_standard_tag_library.htm
Advertisements