JSP JSTL < x: out > tag: output XML information


Example

<%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
  <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <c:import url="bookInfo.xml" var="xmlFile"charEncoding="gbk"/>
    <x:parse var="bookInfo" doc="${xmlFile}"></x:parse>
    编号:<x:out select="$bookInfo/books/book/id/@value"/><br>
    书名:<x:out select="$bookInfo/books/book/name"escapeXml="true"/><br>
    出版社:<x:out select="$bookInfo/books/book/publish/@value"/>
<?xml version="1.0"encoding="gbk"?>
<books>
  <book>
    <id value="1"/>
    <name>&lt;&lt;Java开发宝典&gt;&gt;</name>
    <author value="C语言中文网"/>
    <publish value="机械工业出版社"/>
  </book>
</books>
书名:<x:out select="$bookInfo/books/book/name"escapeXml="true"/>
书名:<x:out select="$bookInfo/books/book/name"escapeXml="false"/>

Typical application

<%@page pageEncoding="gbk" contentType="text/html;charset=GBK"%>
  <%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
    <%@taglib prefix="c" uri="/WEB-INF/c.tld"%>
      <c:import url="book.xml" var="xmlFile" charEncoding="gb2312"/>
      <x:parse var="tushu" doc="${xmlFile}"/>
      <table width="300" border="1" cellpadding="0" cellspacing="0"
             bordercolor="white" bordercolordark="white" bordercolorlight="black">
        <tr>
          <td bgcolor="gray">ID:</td><td>
          <x:out select="$tushu/books/book/id/@value"/></td>
        </tr>
        <tr>
          <td bgcolor="gray">NAME:</td><td>
          <x:out select="$tushu/books/book/name/@value"/></td>
        </tr>
        <tr>
          <td bgcolor="gray">PUBLISH:</td>
          <td><x:out select="$tushu/books/book/publish/@value"/></td>
        </tr>
        <tr>
          <td bgcolor="gray">PRICE:</td>
          <td><x:out select="$tushu/books/book/price/@value"/></td>
        </tr>
      </table>
<?xml version="1.0" encoding="gbk"?>
<books>
  <book>
    <id value="9787111378471"/>
    <name value="Java开发宝典"/>
    <publish value="机械工业出版社"/>
    <price value="99.00"/>
  </book>
</books>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>