<x:parse> 标签

约 1371 字 更新于 2026-11-18 5iyo.com

<x:parse> 标签

<x:parse>标签用来解析属性中或标签主体中的XML数据。

语法格式


<x:parse

  var="<string>"

  varDom="<string>"

  scope="<string>"

  scopeDom="<string>"

  doc="<string>"

  systemId="<string>"

  filter="<string>"/>

属性

<x:parse>标签有如下属性:

属性 描述 是否必要 默认值
var 包含已解析XML数据的变量 否 无
xml 需要解析的文档的文本内容(String或Reader) 否 Body
systemId 系统标识符URI,用来解析文档 否 无
filter 应用于源文档的过滤器 否 无
doc 需要解析的XML文档 否 Page
scope var属性的作用域 否 Page
varDom 包含已解析XML数据的变量 否 Page
scopeDom varDom属性的作用域 否 Page


实例演示

接下了的例子告诉我们如何解析一个XML文档:

books.xml文件代码如下:


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

main.jsp文件代码如下:


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

运行结果如下:


BOOKS INFO:

The title of the first book is:Padam History 

The price of the second book: 2000