English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

<x:parse> Tag

JSP Standard Tag Library

The <x:parse> tag is used to parse XML data in attributes or tag bodies.

Syntax format

<x:parse
  var="<string>"
  varDom="<string>"
  scope="<string>"
  scopeDom="<string>"
  doc="<string>"
  systemId="<string>"
  filter="<string>"/>

Attribute

The <x:parse> tag has the following attributes:

Attribute Description Whether necessary Default value
var Variables containing parsed XML data No None
xml The text content of the document to be parsed (String or Reader) No Body
systemId System identifier URI, used to parse the document No None
filter The filter applied to the source document No None
doc The XML document to be parsed No Page
scope The scope of the var attribute No Page
varDom Variables containing parsed XML data No Page
scopeDom The scope of the varDom attribute No Page

Example demonstration

The following examples show us how to parse an XML document:

The code of the books.xml file is as follows:

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

The main.jsp file code is as follows:

<%@ page language="java" contentType="text/html; charset=UTF-8"/html; charset=UTF-8-8"
    pageEncoding="UTF-8"%>
<%@ 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 Tag</title>
</head>
<body>
<h2>Books Info:</h2>
<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>

The running result is as follows:

BOOKS INFO:
The title of the first book is:Padam History 
The price of the second book: 2000

JSP Standard Tag Library