You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Kirchhoff, Lars" <La...@wincor-nixdorf.com> on 2002/11/28 11:49:46 UTC

XMLForm and Table output

Hi, 

it's me again and I hope I'm still getting answers and not starting to
bother you all
with all my questions.
I've tried to create an application which simple should get some user data
from a 
database, by simply enter the name. So my first form is just a text field
where the name
can be inserted. If the name is found all data will be shown. so far so
good. But now
I would like to built something more. Because I do not look at the exact
name in the 
database it could be possible to get more then one entry. I now want to
create a page, 
where all possible names are shown and some more additional information
about them.
So what I would like to have should be looking like this:
      ----------------------------------------------
      | name   | address   | city     | zip        |
      ----------------------------------------------
      | name1  | address1  | city1    | zip1       |
      | name2  | address2  | city2    | zip2       |
      | name3  | address3  | city3    | zip3       |
      | ...    | ...       | ...      | ...        |

where the user has the possibility to click on the a name to get the full
detail.
So what I thought is to write a method which get me the data from the
database and
put this in a DOM Nodes. I thought this would enable me to use them in the
<xf:repeat>
statement, but unfortunately it didn't worked out so far. 

Here is the code I used to create the DOM Nodes:
----------------------------------------------------------------------------
---------------
   // ========================================================
   // Use DOM nodes to store values
   // ========================================================
   DOMImplementation impl;
 		
   try {
	DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
	factory.setNamespaceAware( false );
	factory.setValidating( false );
	DocumentBuilder builder = factory.newDocumentBuilder();
	impl = builder.getDOMImplementation(); 		
   }
   catch ( Exception e ) {
	throw new RuntimeException( "Failed to initialize DOM factory. Root
cause: \n" + e );	
   }
 		
   // ========================================================
   // Use DOM nodes to store values
   // ========================================================
 	Document doc 	= impl.createDocument( null, "Users", null );
 	Node root 	= doc.getDocumentElement();
 	Node custname 	= null;
 	Node address 	= null;
 	Node zip 		= null;
 	Node city		= null;
 	Node user 	= null;
	Text text;	
		
	try {
		Class.forName( "org.postgresql.Driver" );
		Connection 	con 		=
DriverManager.getConnection( DB_URL, DB_USER, DB_PASS );
		Statement 	stmt		= con.createStatement();
		String 		update	= "select custname, busname,
address, city, state, zip, pobox, pocode from customer where custname like
'%" + name + "%'";
		ResultSet 	rs 		= stmt.executeQuery( update
);	 
			
		while ( rs.next() ) {		
			user 	= doc.createElement( "user" );
			root.appendChild( user );
				
			custname 	= doc.createElement( "custname" );

			text 	= doc.createTextNode( rs.getString(
"custname" ) );
			custname.appendChild( text );
			user.appendChild( custname );
			
			address 	= doc.createElement( "address" );

			text 	= doc.createTextNode( rs.getString(
"address" ) );
			address.appendChild( text );
			user.appendChild( address );
			
			zip 		= doc.createElement( "zip" );

			text 	= doc.createTextNode( rs.getString( "zip" )
);
			zip.appendChild( text );
			user.appendChild( zip );
			
			city 	= doc.createElement( "city" );

			text 	= doc.createTextNode( rs.getString( "city" )
);
			city.appendChild( text );
			user.appendChild( city );
							
			system = root;
		}
	} 
	catch( Exception e ) { }
----------------------------------------------------------------------------
---------------

I expected to create the following structure with it:

<users>
	<user>
		<custname></custname>
		<address></address>
		<zip></zip>
		<city></city>
	</user>
	<user>
		<custname></custname>
		<address></address>
		<zip></zip>
		<city></city>
	</user>
</users>

So what I'm now wondering is, if I'm on the right track and just doing some
beginner mistakes
or if this won't work at all. 

Thanks in advance that you read up to here.

ciao Lars

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: XMLForm and Table output

Posted by Ivelin Ivanov <iv...@apache.org>.
Yes. You are on the right track.
Why don't you print the XML document once it is created to see what it
actually contains.
I suspect this might be a simple mistake due to misuse of the API. It is not
very convenient.
Actually if you plan writing a lot of DOM code, you may want to look at JDOM
or some of the O/R mapping frameworks.


Ivelin



----- Original Message -----
From: "Kirchhoff, Lars" <La...@wincor-nixdorf.com>
To: "Cocoon-Users (E-Mail)" <co...@xml.apache.org>
Sent: Thursday, November 28, 2002 4:49 AM
Subject: XMLForm and Table output


> Hi,
>
> it's me again and I hope I'm still getting answers and not starting to
> bother you all
> with all my questions.
> I've tried to create an application which simple should get some user data
> from a
> database, by simply enter the name. So my first form is just a text field
> where the name
> can be inserted. If the name is found all data will be shown. so far so
> good. But now
> I would like to built something more. Because I do not look at the exact
> name in the
> database it could be possible to get more then one entry. I now want to
> create a page,
> where all possible names are shown and some more additional information
> about them.
> So what I would like to have should be looking like this:
>       ----------------------------------------------
>       | name   | address   | city     | zip        |
>       ----------------------------------------------
>       | name1  | address1  | city1    | zip1       |
>       | name2  | address2  | city2    | zip2       |
>       | name3  | address3  | city3    | zip3       |
>       | ...    | ...       | ...      | ...        |
>
> where the user has the possibility to click on the a name to get the full
> detail.
> So what I thought is to write a method which get me the data from the
> database and
> put this in a DOM Nodes. I thought this would enable me to use them in the
> <xf:repeat>
> statement, but unfortunately it didn't worked out so far.
>
> Here is the code I used to create the DOM Nodes:
> --------------------------------------------------------------------------
--
> ---------------
>    // ========================================================
>    // Use DOM nodes to store values
>    // ========================================================
>    DOMImplementation impl;
>
>    try {
> DocumentBuilderFactory factory =
> DocumentBuilderFactory.newInstance();
> factory.setNamespaceAware( false );
> factory.setValidating( false );
> DocumentBuilder builder = factory.newDocumentBuilder();
> impl = builder.getDOMImplementation();
>    }
>    catch ( Exception e ) {
> throw new RuntimeException( "Failed to initialize DOM factory. Root
> cause: \n" + e );
>    }
>
>    // ========================================================
>    // Use DOM nodes to store values
>    // ========================================================
>   Document doc = impl.createDocument( null, "Users", null );
>   Node root = doc.getDocumentElement();
>   Node custname = null;
>   Node address = null;
>   Node zip = null;
>   Node city = null;
>   Node user = null;
> Text text;
>
> try {
> Class.forName( "org.postgresql.Driver" );
> Connection con =
> DriverManager.getConnection( DB_URL, DB_USER, DB_PASS );
> Statement stmt = con.createStatement();
> String update = "select custname, busname,
> address, city, state, zip, pobox, pocode from customer where custname like
> '%" + name + "%'";
> ResultSet rs = stmt.executeQuery( update
> );
>
> while ( rs.next() ) {
> user = doc.createElement( "user" );
> root.appendChild( user );
>
> custname = doc.createElement( "custname" );
>
> text = doc.createTextNode( rs.getString(
> "custname" ) );
> custname.appendChild( text );
> user.appendChild( custname );
>
> address = doc.createElement( "address" );
>
> text = doc.createTextNode( rs.getString(
> "address" ) );
> address.appendChild( text );
> user.appendChild( address );
>
> zip = doc.createElement( "zip" );
>
> text = doc.createTextNode( rs.getString( "zip" )
> );
> zip.appendChild( text );
> user.appendChild( zip );
>
> city = doc.createElement( "city" );
>
> text = doc.createTextNode( rs.getString( "city" )
> );
> city.appendChild( text );
> user.appendChild( city );
>
> system = root;
> }
> }
> catch( Exception e ) { }
> --------------------------------------------------------------------------
--
> ---------------
>
> I expected to create the following structure with it:
>
> <users>
> <user>
> <custname></custname>
> <address></address>
> <zip></zip>
> <city></city>
> </user>
> <user>
> <custname></custname>
> <address></address>
> <zip></zip>
> <city></city>
> </user>
> </users>
>
> So what I'm now wondering is, if I'm on the right track and just doing
some
> beginner mistakes
> or if this won't work at all.
>
> Thanks in advance that you read up to here.
>
> ciao Lars
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>