<x:parse> Tag
The <x:parse>
tag is used to parse XML data contained in attributes or the body of the tag.
Syntax
<x:parse
var="<string>"
varDom="<string>"
scope="<string>"
scopeDom="<string>"
doc="<string>"
systemId="<string>"
filter="<string>"/>
Attributes
The <x:parse>
tag has the following attributes:
Attribute | Description | Required | Default Value |
---|---|---|---|
var | Variable containing the parsed XML data | No | None |
xml | Text content of the document to be parsed (String or Reader) | No | Body |
systemId | System identifier URI for document parsing | No | None |
filter | Filter applied to the source document | No | None |
doc | XML document to be parsed | No | Page |
scope | Scope of the var attribute | No | Page |
varDom | Variable containing the parsed XML data | No | Page |
scopeDom | Scope of the varDom attribute | No | Page |
Example Demonstration
The following example demonstrates how to parse an XML document:
The books.xml
file contains:
<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 contains:
<%@ page language="java" contentType="text/html; charset=UTF-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>
<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>
The output is:
BOOKS INFO:
The title of the first book is: Padam History
The price of the second book: 2000