<x:parse>-Tag
Das Tag <x:parse> wird verwendet, um XML-Daten in Attributen oder Tag-Inhalten zu parsen.
Syntax
<x:parse var="<string>" varDom="<string>" scope="<string>" scopeDom="<string>" doc="<string>" systemId="<string>" filter="<string>"/>
Attribute
Das <x:parse>-Tag hat die folgenden Attribute:
| Attribute | Beschreibung | Erforderlich | Standardwert |
|---|---|---|---|
| var | Variable, die geparste XML-Daten enthält | nein | Keine |
| xml | Textinhalt des zu parsenden Dokuments (String oder Reader) | nein | Body |
| systemId | System-Identifier-URI, der zum Parsen des Dokuments verwendet wird | nein | Keine |
| filter | Filter, der auf das Quelldokument angewendet wird | nein | Keine |
| doc | Zu parsende XML-Dokument | nein | Page |
| scope | Gültigkeitsbereich des var-Attributs | nein | Page |
| varDom | Variable, die geparste XML-Daten enthält | nein | Page |
| scopeDom | Gültigkeitsbereich des varDom-Attributs | nein | Page |
Beispiele
Das folgende Beispiel zeigt, wie man ein XML-Dokument parst:
Der Code der Datei books.xml lautet wie folgt:
<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>
Der Code der Datei main.jsp sieht wie folgt aus:
<%@ 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>
Das Ausgabeergebnis ist wie folgt:
BOOKS INFO: The title of the first book is:Padam History The price of the second book: 2000
Andere Erweiterungen
JSP-Standard-Tag-Bibliothek