Jstl Tag Library: XML tag Library

Source: Internet
Author: User
Tags foreach expression range requires xpath xslt

JSTL provides a tag library for manipulating XML files, and using XML tag libraries eliminates the complexity of using DOM and sax tag libraries to easily read the contents of XML files.

1 XML Core Tag Library

1. <x:parse> Label

The <x:parse/> tab is used to parse the specified XML file.

"Syntax 1":

<x:parse doc= "XmlDocument" {var= "name" [scope= "Page|request|session|application"]|vardom= "name" [Scope=] page| Request|session|application "]}

Systemid= "SystemID" filter= "filter"/>

"Syntax 2":

<x:parse {var= "name" [scope= "Page|request|session|application"]|vardom= "name" [scope= "page|request|session|"] Application "]}

Systemid= "SystemID" filter= "Filter" >

XmlDocument

</x:parse>

<x:parse> Label Attribute Description

Attribute Name: Description: EL: Type: must: Default value

Doc: Specify the parsed XML file: Yes: String/reader: Yes: no

var: store parsed XML file: No: String: No: None

Scope: Specify the range of JSP for VAR: no: No: page

Vardom: Storing resolved XML files in (Org.w3c.dom.Doucemet): No: String: No: None

Scopedom: Specify the JSP range for Vardom: No: String: No: Page

URL of systemid:xml file: Yes: String: No: None

Filter: Filters for parsing XML files: No: Org.xml.sax.Filter: No: No

Tip: doc Specifies that the parsed XML file is not the path to the specified XML file, but is used in conjunction with <c:import>, loaded and stored by <c:import>, and then used <x:parse> parsing.

For example, parsing an person.xml file requires parsing the XML file through the following code.

<c:import var= "docstring" url= "person.xml"/><!--introduced person.xml file-->

<x:parse var= "Doc" doc= "${docstring}"/>

<c:import> statements are used to import or store files into JSPs. If you do not use Var to store, the XML file will appear explicitly in the JSP file.

<x:parse> tags are only used to parse XML files, do not display the contents of XML files, if you want to get XML node elements or values need to use the <x:out> element to implement.

2. <x:out> Label

<x:out> tags are primarily used to output XML information.

"Syntax":

<x:out select= "Xpathexperssion" [excapexml= "True|false"]>

<x:out> Label Attribute Description

Attribute Name: Description: EL: Type: must: Default value

Select: Specify XPath statement to use: No: String: Yes: none

EscapeXML: Converts special characters. such as <: No: Boolean: Yes: True

Hint: Using an XPath statement requires a Xalan.jar support package, which can be obtained from the Lib of the sample program and can be found directly from the MyEclipse.

3. <x:set> Label

The <x:set> tab is used to store content parsed from the XML file node into the JSP property scope.

"Syntax":

<x:set select= "xpathexperssion" var= "name" scope= "Page|request|session|application" >

"Parameter description":

(1) Select gets the value of the node through the specified XPath expression statement.

(2) var specifies the name of the variable used to store the value.

(3) Specify the range of JSP properties for Var.

2 XML Process Control

Process Control tags using XML tag libraries can iterate over the contents of XML files, and process control can be divided into the following two areas:

(1) Conditional judgment.

(2) Circulation function.

2.1. <x:if>

<x:if> is mainly used for conditional judgment.

"Syntax 1": does not contain ontology content.

<x:if select= "xpathexperssion" var= "name" [scope= "Page|request|session|application"]/>

"Syntax 2": Contains ontology content.

<x:if select= "xpathexperssion" var= "name" [scope= "Page|request|session|application"]>

Ontology content

</x:if>

Syntax 1 only stores the results of a conditional expression in the JSP scope, and Syntax 2 determines whether or not to execute the code in this body based on the result of the conditional expression according to the <x:if> label.

"Parameter description":

(1) Select to specify the xpathexperssion expression to use.

(2) var sets a scalar name to store the result of an expression.

(3) scope specifies the range of JSP properties for the Var store.

2.2. <x:choose>, <x:when> and <x:otherwise> labels

Similar to the <c:choose>, <c:when> and <c:otherwise> tags of the core tag library, only the conditional expressions are used differently.

<x;choose> is the main label,<x:when> and <x:otherwise> placed in the <x:choose> tag body for common use.

"Syntax":

<x:choose>

<x:when>

<x:when>

<x:otherwise>

</x:choose>

Only <x:when> has attributes.

"Syntax":

<x:when select= "Xpathexperssion" >

2.3. <x:forEach> Label

The <x;forEach> tag implements the traversal of XML documents.

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/JSP/

"Syntax":

<x:foreach select= "Xpathexperssion" [var= "name"][varstartus= "Startusname"] [begin= "Begin"][end= "End"][step= "] Step "]>

Label body

</x:forEach>

<x:forEach> Label Attribute Description

Attribute Name: Description: EL: Type: must: Default value

Select: Specify XPath statement to use: No: String: Yes: none

var: used to store the result of an expression: No: String: No: None

Varstatus: Information about the variables to be stored in the loop: No: No. String: No: None

Begin: The starting position of the loop:: int: No: None

End: Where the loop ends: yes: int: no: None

3 File conversions of XML

<x:transform> and <x:param> can easily wrap XML files using XSLT styles as another way of showing.

1. <x:transform> Label

With this tag, you can easily transform XML into XSLT.

"Syntax 1":

<x:transform doc= "xmldoc" xslt= "Xsltstytlesheet" [docsystemid= "Xmlsystemid"][result= "result"][var= "name"] [ Scope= "ScopeName"][xsltsystemid= "Xsltsystemid"]/>

"Syntax 2":

<x:transform doc= "xmldoc" xslt= "Xsltstytlesheet" [docsystemid= "Xmlsystemid"][result= "result"][var= "name"] [ Scope= "ScopeName"][xsltsystemid= "Xsltsystemid"]>

<x:param/>

</x:transform>

"Syntax 3":

<x:transform doc= "xmldoc" xslt= "Xsltstytlesheet" [docsystemid= "Xmlsystemid"][result= "result"][var= "name"] [ Scope= "ScopeName"][xsltsystemid= "Xsltsystemid"]>

XML file contents

<x:param/>

</x:transform>

<x:transform> Label Attribute Description

Attribute Name: Description: EL: Type: must: Default value

Doc: Specify the source of the XML file: Yes: String: Yes: none

XSLT: A style template that transforms xml: Yes: String: Yes: none

URI of Docsystemid:xml file: Yes: String: No: None

URI of xsltsystemid:xslt file: Yes: String: No: None

Result: Used to store the converted outcome objects: Java.xml.transform: Yes: no

var: storing converted results as Org.w3c.dom.Documet: No: String: No: None

Scope:var Property Range: No: String: No: None

2. <x:param> Label

The label is used to convert parameters for the <x:transform> tag.

"Syntax 1":

<x:param name= "name" value= "value"/>

"Syntax 2":

<x:param name= "name" value= "Value" >

Value

</x:param>

"Parameter description":

(1) name specifies the names of the parameters.

(2) value specifies the value of the parameter.

Author: csdn blog Bujikuibu Small stream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.