<%@ page language="java" contentType="text/plain" %>
<%@ taglib uri="http://www.dbxml.com/db/jsp" prefix="dbxml" %>

<%--
   Connect to the Database.
   Creates a dbXMLClient variable called local
--%>
<dbxml:connection name="local" driver="com.dbxml.db.client.xmlrpc.dbXMLClientImpl">
   <dbxml:property name="connection" value="secure"/>
</dbxml:connection>

<%--
   Retrieve a Collection reference.  Will look for the
   dbXMLClient variable identified by connection and will
   create a CollectionClient variabled called users.
--%>
<dbxml:collection name="users" path="/users" connection="local"/>

<%--
   Inserts the enclosed Document into the Database.  Will
   look for a CollectionClient variable identified by
   collection and will create a String variable called userID
   that contains the ID of the newly inserted Document.

   The semantics for set are similar, except that the key
   attribute is used to explicitly name the document, and
   no variable assignment takes place (no name attribute).
--%>
<dbxml:insert name="userID" collection="users" >
<user>
   <firstname><%= request.getParameter("first_name") %></firstname>
   <lastname><%= request.getParameter("last_name") %></lastname>
   <address1><%= request.getParameter("address1") %></address1>
   <address2><%= request.getParameter("address2") %></address2>
   <city><%= request.getParameter("city") %></city>
   <state><%= request.getParameter("state") %></state>
   <postalcode><%= request.getParameter("zip") %></postalcode>
</user>
</dbxml:insert>

Working Document: <%= userID %>

<%--
   Fetches the newly inserted Document and appends it to
   the output stream.  Will look for a CollectionClient variable
   identified by collection.
--%>
<dbxml:get collection="users" key="<%= userID %>" prefix="false"/>

<%--
   Issues the specified query.  Will look for a CollectionClient
   specified by collection and will create a ResultSetClient
   variable called results that contains the query results.
--%>
<dbxml:query name="results" collection="users" style="XPath">
   /user[lastname[starts-with(., 'B')]]/firstname/text()
</dbxml:query>

<%--
   Iterates over a generated Query result set.  Will look for a
   ResultSetClient specified by query and will create several
   in-scope variables, including col, key, and result.
--%>
<dbxml:iterator query="results" text="true">
   <user><%= result %></user>
</dbxml:iterator>


<%--
   Removes a Document from the Collection.  Will look for a
   CollectionClient specified by collection and will delete
   the Document identified by key.
--%>
<dbxml:remove collection="users" key="<%= userID %>" />
