Latest web development tutorials

<X: parse> tag

JSP standard Tag Library JSP standard Tag Library

<X: parse> est utilisée pour résoudre les données propriété du corps de balise ou XML.

syntaxe

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

propriété

<X: parse> balise a les attributs suivants:

propriété description le cas échéant Par défaut
var Il contient des variables de données XML analysé aucun aucun
xml Nécessité d'analyser le texte du contenu du document (String ou Reader) aucun corps
systemId Identifiant système URI est utilisé pour analyser le document aucun aucun
filtre Les filtres utilisés dans le document source, aucun aucun
doc Besoin d'analyser des documents XML aucun page
portée attribut var Scope aucun page
varDom Il contient des variables de données XML analysé aucun page
scopeDom Portée propriété varDom aucun page


Exemples Démo

Il a pris le cas pour nous dire comment analyser un document XML:

Code de fichier books.xml est la suivante:

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

Code de fichier main.jsp est la suivante:

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

Les résultats sont les suivants:

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

JSP standard Tag Library JSP standard Tag Library