Balise <x:parse>
Bibliothèque de balises standard JSP
La balise <x:parse> est utilisée pour analyser des données XML dans les attributs ou le corps des balises.
Syntaxe
<x:parse var="<string>" varDom="<string>" scope="<string>" scopeDom="<string>" doc="<string>" systemId="<string>" filter="<string>"/>
Attributes
La balise <x:parse> possède les attributs suivants :
| Attribut | Description | Requis | Valeur par défaut |
|---|---|---|---|
| var | Variable contenant les données XML analysées | non | Aucune |
| xml | Texte du document à analyser (String ou Reader) | non | Body |
| systemId | Identifiant système utilisé pour analyser le document | non | Aucune |
| filter | Filtre appliqué au document source | non | Aucune |
| doc | Document XML à analyser | non | Page |
| scope | Portée de l'attribut var | non | Page |
| varDom | Variable contenant les données XML analysées | non | Page |
| scopeDom | Portée de l'attribut varDom | non | Page |
Exemples
L'exemple suivant montre comment analyser un document XML :
Le code du fichier books.xml est le suivant :
<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>
Le code du fichier main.jsp est le suivant :
<%@ 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>
Le résultat de sortie est le suivant :
BOOKS INFO: The title of the first book is:Padam History The price of the second book: 2000
Autres extensions