如何在 JSP 中列印 XPath 表示式結果?
<x:out> 標籤顯示 XPath 表示式的結果。它與 <%= %> JSP 語法具有相同的功能。
屬性
<x:out> 標籤具有以下屬性 −
| 屬性 | 描述 | 必需 | 預設 |
|---|---|---|---|
| select | 通常使用 XPath 變數,將 XPath 表示式作為字串求值 | 是 | 無 |
| escapeXml | 如果該標籤應轉義 XML 特殊字元,則為 True | 否 | true |
示例
我們來看一個示例,介紹標籤 (a) <x:out>、(b) <x:parse>。
<%@ 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:out Tags</title>
</head>
<body>
<h3>Books Info:</h3>
<c:set var = "xmltext">
<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>
</c:set>
<x:parse xml = "${xmltext}" 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>以上程式碼將生成以下結果 −
Books Info: The title of the first book is: Padam History The price of the second book: 2000
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP