Etiqueta <x:parse>
Biblioteca de etiquetas estándar de JSP
La etiqueta <x:parse> se utiliza para analizar datos XML en atributos o en el cuerpo de la etiqueta.
Formato de sintaxis
<x:parse var="<string>" varDom="<string>" scope="<string>" scopeDom="<string>" doc="<string>" systemId="<string>" filter="<string>"/>
Atributos
La etiqueta <x:parse> tiene los siguientes atributos:
| Atributo | Descripción | Necesario | Valor predeterminado |
|---|---|---|---|
| var | Variable que contiene los datos XML analizados. | no | Ninguno |
| xml | Contenido de texto del documento a analizar (String o Reader) | no | Body |
| systemId | URI del identificador de sistema, utilizado para analizar el documento. | no | Ninguno |
| filter | Filtro aplicado al documento fuente. | no | Ninguno |
| doc | Documento XML a analizar. | no | Page |
| scope | Alcance del atributo var. | no | Page |
| varDom | Variable que contiene los datos XML analizados. | no | Page |
| scopeDom | Alcance del atributo varDom. | no | Page |
Ejemplo de demostración
El siguiente ejemplo nos muestra cómo analizar un documento XML:
El código del archivo books.xml es el siguiente:
<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>
El código del archivo main.jsp es el siguiente:
<%@ 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>
El resultado de la ejecución es el siguiente:
BOOKS INFO: The title of the first book is:Padam History The price of the second book: 2000
Otras extensiones