Jsp-jstl-xml-parse-tag

提供:Dev Guides
移動先:案内検索

JSTL-XML <x:parse>タグ

*<x:parse>* タグは、属性またはタグ本文で指定されたXMLデータを解析するために使用されます。

属性

*<x:parse>* タグには次の属性があります-
Attribute Description Required Default
var A variable that contains the parsed XML data No None
xml Text of the document to parse (String or Reader) No Body
systemId The system identifier URI for parsing the document No None
filter The filter to be applied to the source document No None
doc XML document to be parsed No Page
scope Scope of the variable specified in the var attribute No Page
varDom A variable that contains the parsed XML data No Page
scopeDom Scope of the variable specified in the varDom attribute No Page

次の例は、解析を使用して外部XMLファイルを読み取る方法を示しています-

特定のドキュメントの本文から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を試してください-

<%@ 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 Tags</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>
*http://localhost:8080/main.jsp* を使用して上記のJSPにアクセスすると、次の結果が表示されます-
Books Info:
The title of the first book is:Padam History
The price of the second book: 2000