[ 
https://issues.apache.org/jira/browse/VELTOOLS-99?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12612538#action_12612538
 ] 

Nathan Bubna commented on VELTOOLS-99:
--------------------------------------

Yeah, Dom4j was just the path of least resistance, since i knew it already and 
we already pulled in the jar for generating VelocityTools docs with DVSL.

I still think JXPath is more than this needs, and i'm not sure what you mean by 
"DVSL like support".  But by all means, post the code if you write it!  Nothing 
sells like a good example. :)

Hmm, i need to update the class Javadoc at the top!  I'm in the practice these 
days of describing a tool's syntax before i create it.  But once i start 
testing and using the code, things sometimes change.  I forgot to go back and 
sync that javadoc with the final version.  It should be:

XML file:
  <foo><bar>woogie</bar><a name="test"/></foo>

Template:
  $foo.bar.text
  $foo.find('a')
  $foo.a.name

Output:
  woogie
  <a name="test"/>
  test

Configuration:
<tools>
  <toolbox scope="application">
    <tool class="org.apache.velocity.tools.generic.XmlTool" key="foo" 
file="doc.xml"/>
  </toolbox>
</tools>

So, if you did just $foo.bar, then that XmlTool instance's toString() would 
produce <bar>woogie</bar>.  It turned out to be too unintuitive in many cases 
for toString() to just render the text of an element, so it renders the xml 
form for everything but Attribute nodes, for which it returns the value.  So, 
yeah, with Velocity 1.5, 

#if( $foo.bar == "<bar>woogie</bar>" && $foo.find('@name') == 'test' ) true 
#end  will work, even though the right of each is a string and the lefts are 
XmlTool instances, since 1.5 falls back to String comparison if the types are 
different.

> XmlTool
> -------
>
>                 Key: VELTOOLS-99
>                 URL: https://issues.apache.org/jira/browse/VELTOOLS-99
>             Project: Velocity Tools
>          Issue Type: New Feature
>          Components: GenericTools
>    Affects Versions: 2.x
>            Reporter: Nathan Bubna
>             Fix For: 2.0
>
>
> There have always been those interested in a general tool to read and utilize 
> XML content in templates.  Various approaches to this have been taken.  
> Though i've yet to need this myself, i thought it would be prudent to gather 
> ideas and links to relevant discussion and implementations here, in case 
> someone gets the itch or we want to come up with ideas for something like the 
> GHOP contest.
> Here's a XmlTool that Christoph Reck posted to the mailing list:
> http://velocity.markmail.org/search/?q=XmlTool#query:XmlTool+page:1+mid:rpogtxshsqqoiph7+state:results
> Philippe Collignon created XmlGen (http://xmlgen.sourceforge.net/), which 
> offers a very simple API for walking XML docs in a template.  There was talk 
> of contributing the whole project, but that fizzled.  As it is ASL 2 
> licensed, we could easily adopt relevant portions or, better, find a way to 
> collaborate and keep the portions we're both interested in in one place.
> DVSL has some useful node selection/handling code that uses Dom4j:
> http://svn.apache.org/repos/asf/velocity/dvsl/trunk/src/java/org/apache/dvsl/dom4j/Dom4jNodeImpl.java
> Anakia, of course, also has some useful xpath/xml handling code:
> http://svn.apache.org/repos/asf/velocity/anakia/trunk/src/java/org/apache/anakia/
> It may also prove useful to somehow combine or connect XML reading with the 
> XML writing stuff proposed in VELTOOLS-97 
> (https://issues.apache.org/jira/browse/VELTOOLS-97)
> And of course, there's probably a lot of other useful XML handling code out 
> there.  At this point, my favorite API by far is XmlGen's which is very 
> Velocity-ish and intuitive to me.  Since XmlGen is a Texen extension and i 
> hope eventually to get around to making VelocityTools integrate naturally 
> into Texen (as well as DVSL and Anakia), it may be that XmlGen's xml reading 
> API(s) could migrate wholly to VelocityTools.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Reply via email to