Re: Fixing the XML wrapper regarding the existence ops - Was: Handling missing node values with NodeModel

Tom Fennelly <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Well... it did "work" perfectly, but I can see that it might not be what 
you'd like.  I was just happy to get something that got me going again 
for now :)

On 21/06/2011 18:28, Daniel Dekany wrote:
>     - myXmlNode.foo means "I want that *single* node". If there are no
>       matches, that's a undefined variable error, thus `!`, `??` etc.
>       works as expected. If there are multiple marching nodes, that's a
>       TemplateModelException, that can't be suppressed (except with
>       #attempt, of course).
I'm sure this my come across as ignorance on my part (and maybe it is :) 
), but as a user... I find exceptions in situations like this (multiple 
matching nodes) to be a bit painful/pickie.  I can see (from a purest 
pov) how an exception may be the "right" thing to do in order to force 
the template author to fix the issue, but I sometimes find that the 
exceptions produced are not always so easy to follow for someone that 
just occasionally uses FreeMarker i.e. it's not always obvious what I 
need to do as a user to get from an error like "/Expecting a string, 
date or number here, Expression .vars["com.acme.Booking"]["checkIn"] is 
instead a freemarker.ext.dom.NodeListModel/" to something that works 
(same with the treatment of nulls).

I suppose I'm saying... if you're going to employ a very strict policy 
in terms of what's accepted (resulting in frequent templating exceptions 
that need to be fixed) then the errors need to be really really good and 
need to help you get back on the road quickly.

I hope that doesn't come across as being critical... FreeMarker is 
awesome and I know that this type of thing is always a huge challenge 
for every framework !!
>     - myXmlNode.foo$ means "I want the list of the matching nodes".
>       This would always return a sequence, even if 0 long. Why "$"?
>       It could be read as the "S" of the plural form, "foos". (I think
>       this was originally the idea of Jonathan.) The drawback is of
>       course that this way we deviate from XPath, so XPath expression
>       couldn't be written as myXmlNode["foo//bar"] and like. Instead,
>       they had to be written as myXmlNode("foo//bar") maybe.
Sounds good.  Might another syntax for saying "I want a list" be 
something like "myXmlNode.foo[]".
> Neither of these are strictly backward-compatible, but since we can
> have multiple wrapper instances and instances can be configured or of
> different classes, that's manageable.
>
> Another thing... I find it scary that we depend on internal API-s to
> do XPath with Xerces. If they still haven't added the required API-s
> as public, well... in the new wrapper we should just require Jaxen.
> Unless, there are performance problems with that or like... anybody is
> aware of such issues?
I know that Jaxen is nice enough to use from an API standpoint... not 
sure about the performance because where I used it I eliminated that as 
a risk - Jaxen was really just used to parse the XPath expressions... 
was not used for evaluating.

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.