XMLTextReader taglib ver. 2.2


    Custom JSP tags. Lets you read and proceed XML files. This approach is similar to XMLTextReader stuff in .NET (actually this taglib uses SAX parser). For example:
 


<%@ taglib uri="taglib.tld" prefix="sax" %>

<sax:XMLTextReader xmlData="c:/files/test.xml">

  <sax:ifNameEquals name="price"><b></sax:ifNameEquals>
    <br>Node name is:<sax:getName/> Node value is:<sax:getValue/>
  <sax:ifNameEquals name="price"></b></sax:ifNameEquals>

</sax:XMLTextReader>

Body tag XMLTextReader iterates over XML nodes. Within this loop you may use tags getName and getValue and read node's value and node's text for current node. The above mentioned example prints all nodes and node named price will be printer with bold font.

Body tag Attributes iterates over attributes for current node. Within this loop you may use tags getAttributeName and getAttributeValue and read name/value for current attribute. For example the code below prints all nodes and their attributes:
 


<sax:XMLTextReader xmlData="c:/files/test.xml">

  <br>Node name is:<sax:getName/> Node value is:<sax:getValue/>
  <sax:Attributes>
     <b><sax:getAttributeName/> = <sax:getAttributeValue/>
  </sax:Attributes>

</sax:XMLTextReader>

Tags are:

XMLTextReader

Reads XML data and iterates over nodes. You may set XML source as one of parameters (xmlString or xmlData). Parameters are:

1) xmlData XML source as a some URL (file).
2) xmlString XML source as a string.
3) ignoreDTD Optional parameter. Possible values are true or false. Lets you ignore external DTD during the parsing. Default value is false.

getName

Reads a name for the current node. Parameters are:

1) id Optional parameter. Describes a page scope variable (type is java.lang.String) for your data. Without this parameter tag just prints data.

getValue

Reads a value for the current node. Parameters are:

1) id Optional parameter. Describes a page scope variable (type is java.lang.String) for your data. Without this parameter tag just prints data.

ifNameEquals

Body tag. Executes own body if node's name is equal to the given value. Parameters are:

1) name name for node

ifNameNotEquals

Body tag. Executes own body if node's name is not equal to the given value. Parameters are:

1) name name for node

Attributes

Body tag. Executes own body for each attribute of current node. Parameters are: none

getAttributeName

Reads a name for the current attribute. Parameters are:

1) id Optional parameter. Describes a page scope variable (type is java.lang.String) for data. Without this parameter tag just prints data.

getAttributeValue

Reads a value for the current attribute. Parameters are:

1) id Optional parameter. Describes page scope variable (type is java.lang.String) for data. Without this parameter tag just prints data.
2) name Optional parameter. Describes a name for the attribute. Without this parameter tag calculates value for the current attribute.

Notes:

1. Taglib uses JAXP for parsing XML.

for downloading:

Library: saxtag.jar    Description: taglib.tld

© Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: