<x:parse> Tag

JSP 标准标签库JSP Standard Tag Library

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

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 parsed XML data no None
xml 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 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 parsed XML data no Page
scopeDom Scope of the varDom attribute no Page


Examples

The following example shows us how to parse an XML document:

The books.xml file code 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"
    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 标签</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 result is as follows:

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

JSP 标准标签库JSP Standard Tag Library

Other Extensions