XML building - velocity 1.4

2006-02-07 Thread Anagha
Hi,
I want to build xml by replacing existing XML text elements with some other
text.
I built the Document with SAXBuilder and put the root element in the
context.
My template is like this :

#set ($rootelem = $root.getRootElement())
$rootelem

#foreach($elem in $rootelem.getChildren())
#set ($newelem = $elem)

#if ($elem.getName().equalsIgnoreCase(serviceInstanceId))
got it
$newelem.getText()
$newelem.setText(OTHERTEXT)
$newelem
#end
#end

When I merge with the template, I get the text of the existing node
correctly( $newelem.getText())
After setText when I print the $newelem I expect the new text (OTHERTEXT) in
the element.
But I get the empty element. I never see new  text element in the element.

Any help is appreciated.

--
Thanks  Regards,
Anagha


Re: XML building - velocity 1.4

2006-02-07 Thread Will Glass-Husain

I've never used SAXBuilder...

Are you sure that $newelem.toString() always displays the same as 
$newelem.getText()


- Original Message - 
From: Anagha [EMAIL PROTECTED]

To: velocity-user velocity-user@jakarta.apache.org
Sent: Tuesday, February 07, 2006 12:34 AM
Subject: XML building - velocity 1.4


Hi,
I want to build xml by replacing existing XML text elements with some other
text.
I built the Document with SAXBuilder and put the root element in the
context.
My template is like this :

#set ($rootelem = $root.getRootElement())
$rootelem

#foreach($elem in $rootelem.getChildren())
   #set ($newelem = $elem)

   #if ($elem.getName().equalsIgnoreCase(serviceInstanceId))
   got it
   $newelem.getText()
   $newelem.setText(OTHERTEXT)
   $newelem
   #end
#end

When I merge with the template, I get the text of the existing node
correctly( $newelem.getText())
After setText when I print the $newelem I expect the new text (OTHERTEXT) in
the element.
But I get the empty element. I never see new  text element in the element.

Any help is appreciated.

--
Thanks  Regards,
Anagha


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XML and velocity

2004-12-04 Thread Shinobu Kawai
Hi Subbiah,

 In my particluar hase I though abt creating an obejct and sending it to the
 context but the XML was generated from an object suing castor at some other
 point in the app and I did not want to convert it into an object again.

I don't know what an object suing castor does, but my first question
would be, might there be a way to get the original object?  (My second
question is going to be, why don't you want to convert it into an
object again?  B))

 What is the best way of solving such a problem.
 I wanted to use Xpath style references in my velocity but could not get it
 to work

I don't have enough experience in XML processing to answer this one. 
Could tools like DVSL be of help?
  http://jakarta.apache.org/velocity/dvsl/

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XML and velocity

2004-12-04 Thread Geir Magnusson Jr
On Dec 2, 2004, at 12:47 PM, Subbiah wrote:
Thank you all for your input, it clears some parts of the quetsion.
As you might have quest I have just started using velocity.(a week)
My generic question on VELOCITY is this.
1.  I see velocity very similar to adding sessions in servlets and 
accessing
them  in the jsp pages. Is this correct ?
No :)
It's mostly used that way - as a rendered for the web - but it's used 
in lots of other places as well.  (For example, the IDEA IDE uses 
velocity for it's templates for comments and headers and such...  it's 
a hoot to use, because you can use the context variables to have 
different javadoc templates for different projects that you work on...)

2. I am using VELOCITY to generate templates for certain messages that 
will
be filled at run time. The input is XML and output is any file. We use
velocity because, the client can change the template anytime his fomat
changes, but after using velocity [I might be wrong] I feel he still 
has to
know the details of the object or java classes to use velocity , for 
example
I use DOM parser, then the client has to know what methods are there 
to make
a change in the template.This is like changing the source code of the
generator one thing he need do is rebuild.

Is this the advantage that velocity provides or are that more that my 
short
sightedness prevenst me from seeing [I am sure there are]
The key then is to not depend on DOM.  digest the document into a class 
that the customer can understand, or if the customer understands the 
XML structure, use something that helps them with that.  A while ago, I 
had a little bean that digested an XML document, and let you just use 
in velocity as :

   $data.author.email
I'll see if I can find it.
geir

Thank you.
~Subbiah
-Original Message-
From: Mike Kienenberger [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 02, 2004 10:04 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: XML and velocity
Subbiah Raman [EMAIL PROTECTED] wrote:
I am trying to use a SAX parser in Velocity context and I
need to do
the following
#set($temp = $root.getRootElement().getChild(email).getText() )
But it throws
org.apache.velocity.exception.ParseErrorException:
Encountered email
In addition to what others have said, you can also use
single-quotes inside your double-quotes.
#set($temp = $root.getRootElement().getChild('email').getText() )
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
Geir Magnusson Jr  +1-203-665-6437
[EMAIL PROTECTED]
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: XML and velocity

2004-12-03 Thread Subbiah
If you put the DOM document itself in the Context, 
 the template designers will have to know how to use DOM.  But 
 if you extract all the data needed in java, and put them in 
 the Context in a more user-friendly fashion

I see your convincing point here. Thank you. 

In my particluar hase I though abt creating an obejct and sending it to the
context but the XML was generated from an object suing castor at some other
point in the app and I did not want to convert it into an object again.

What is the best way of solving such a problem. 
I wanted to use Xpath style references in my velocity but could not get it
to work

Any directions here.

Thanks for your replies though !!! 

 -Original Message-
 From: Shinobu Kawai [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, December 02, 2004 11:02 PM
 To: Velocity Users List
 Subject: Re: XML and velocity
 
 
 Hi Subbiah,
 
  My generic question on VELOCITY is this.
  1.  I see velocity very similar to adding sessions in servlets and 
  accessing them  in the jsp pages. Is this correct ?
 
 In a way, yes.  In Velocity, you put stuff in the Context, 
 and then you can access them from the template.  In addition 
 to that you have access to some easy-to-use directives.  :)
 http://jakarta.apache.org/velocity/user-guide.html#Directives
 
  2. I am using VELOCITY to generate templates for certain 
 messages that 
  will be filled at run time. The input is XML and output is 
 any file. 
  We use velocity because, the client can change the template anytime 
  his fomat changes, but after using velocity [I might be 
 wrong] I feel 
  he still has to know the details of the object or java 
 classes to use 
  velocity , for example I use DOM parser, then the client 
 has to know 
  what methods are there to make a change in the 
 template.This is like 
  changing the source code of the generator one thing he need 
 do is rebuild.
  
  Is this the advantage that velocity provides or are that 
 more that my 
  short sightedness prevenst me from seeing [I am sure there are]
 
 VTL itself is a very simple language.  The problem here is 
 that you aren't being friendly to the template designers (the 
 client).  If you put the DOM document itself in the Context, 
 the template designers will have to know how to use DOM.  But 
 if you extract all the data needed in java, and put them in 
 the Context in a more user-friendly fashion (like custom 
 JavaBeans), the only things the template designers need to 
 know are the reference names of the information plus maybe 
 some custom methods for doing special things.
 
 Good luck with Velocity!  ;)
 
 Best regards,
 -- Shinobu Kawai
 
 --
 Shinobu Kawai [EMAIL PROTECTED] 
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



XML and velocity

2004-12-02 Thread Subbiah Raman
Hi,
I am trying to use a SAX parser in Velocity context and I need to do the 
following

#set($temp = $root.getRootElement().getChild(email).getText() )
But it throws
org.apache.velocity.exception.ParseErrorException: Encountered email
Any suggestions.
Thx
_
Choose what you want to read. Protect your mail from spam. 
http://server1.msn.co.in/sp04/hotmailspamcontrol/  Win the war in 9 steps!

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: XML and velocity

2004-12-02 Thread Claude Brisson
On Thu, 2004-12-02 at 12:48, Subbiah Raman wrote:
 Hi,
 I am trying to use a SAX parser in Velocity context and I need to do the 
 following
 
 #set($temp = $root.getRootElement().getChild(email).getText() )
 
 But it throws
 org.apache.velocity.exception.ParseErrorException: Encountered email

There's an unclosed in your statement.
Also, you can simplify the syntax of the getters that take no argument.

Try :

#set($temp = $root.rootElement.getChild(email).text )

Claude



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XML and velocity

2004-12-02 Thread Mike Kienenberger
Subbiah Raman [EMAIL PROTECTED] wrote:
 I am trying to use a SAX parser in Velocity context and I need to do the 
 following
 
 #set($temp = $root.getRootElement().getChild(email).getText() )
 
 But it throws
 org.apache.velocity.exception.ParseErrorException: Encountered email

In addition to what others have said, you can also use single-quotes inside 
your double-quotes.

#set($temp = $root.getRootElement().getChild('email').getText() )

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: XML and velocity

2004-12-02 Thread Subbiah
Thank you all for your input, it clears some parts of the quetsion.
As you might have quest I have just started using velocity.(a week)

My generic question on VELOCITY is this.
1.  I see velocity very similar to adding sessions in servlets and accessing
them  in the jsp pages. Is this correct ?

2. I am using VELOCITY to generate templates for certain messages that will
be filled at run time. The input is XML and output is any file. We use
velocity because, the client can change the template anytime his fomat
changes, but after using velocity [I might be wrong] I feel he still has to
know the details of the object or java classes to use velocity , for example
I use DOM parser, then the client has to know what methods are there to make
a change in the template.This is like changing the source code of the
generator one thing he need do is rebuild.

Is this the advantage that velocity provides or are that more that my short
sightedness prevenst me from seeing [I am sure there are]

Thank you.

~Subbiah
 -Original Message-
 From: Mike Kienenberger [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, December 02, 2004 10:04 AM
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: XML and velocity
 
 Subbiah Raman [EMAIL PROTECTED] wrote:
  I am trying to use a SAX parser in Velocity context and I 
 need to do 
  the following
  
  #set($temp = $root.getRootElement().getChild(email).getText() )
  
  But it throws
  org.apache.velocity.exception.ParseErrorException: 
 Encountered email
 
 In addition to what others have said, you can also use 
 single-quotes inside your double-quotes.
 
 #set($temp = $root.getRootElement().getChild('email').getText() )
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XML and velocity

2004-12-02 Thread Shinobu Kawai

Hi Subbiah,

 My generic question on VELOCITY is this.
 1.  I see velocity very similar to adding sessions in servlets and accessing
 them  in the jsp pages. Is this correct ?

In a way, yes.  In Velocity, you put stuff in the Context, and then you
can access them from the template.  In addition to that you have access
to some easy-to-use directives.  :)
http://jakarta.apache.org/velocity/user-guide.html#Directives

 2. I am using VELOCITY to generate templates for certain messages that will
 be filled at run time. The input is XML and output is any file. We use
 velocity because, the client can change the template anytime his fomat
 changes, but after using velocity [I might be wrong] I feel he still has to
 know the details of the object or java classes to use velocity , for example
 I use DOM parser, then the client has to know what methods are there to make
 a change in the template.This is like changing the source code of the
 generator one thing he need do is rebuild.
 
 Is this the advantage that velocity provides or are that more that my short
 sightedness prevenst me from seeing [I am sure there are]

VTL itself is a very simple language.  The problem here is that you
aren't being friendly to the template designers (the client).  If you
put the DOM document itself in the Context, the template designers will
have to know how to use DOM.  But if you extract all the data needed in
java, and put them in the Context in a more user-friendly fashion (like
custom JavaBeans), the only things the template designers need to know
are the reference names of the information plus maybe some custom
methods for doing special things.

Good luck with Velocity!  ;)

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai [EMAIL PROTECTED] 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]