Re: XMLProcessing : testing optional value in a NodeModel

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Wednesday, February 6, 2008, 9:58:49 AM, Daniel López wrote:

> Hi,
> The explanation is clear and rational, but given that there cannot be 
> two attributes in one node with the same name, it feels 
> counter-intuitive to think in terms of "a sequence" when dealing with 
> node attributes, which probably explains why this sintax issues bites 
> people regularly.

It's surely counter-intuitive, but back then the author wanted to
follow the XPath way of thinking... too bad it plays bad with the
existence operators, which are not designed to check empty VS
non-empty sequences. (But BTW, there can be multiple attribute values
in that sequence, for example, book.chapter.@title, will give you the
list of titles.)

> Coming from a XML/XSLT/Xpath background, I'm afraid FreeMarker's syntax
> to deal with XML does not feel intuitive. Using this case as an example,
> why would one want to check if the "sequence of attributes exist" 
> (connection.@saveDir??) if the only way it can exist is if there is one,
> so I will always have to use (connection.@saveDir[0]??). The same thing
> happens in many cases with nodes, as checking if "it exists" is often 
> useless as one has to check if the size of the sequence is greater than
> zero.
>
> However, don't take that as a complain against FreeMarker. It's just 
> that the syntax is "close" to XPath but "not that close" and that causes
> confusion to people with experience with XPath.

This could be fixed with another XML wrapper that uses a different
approach... Technically, anyone can write a custom one.

> And the "conditional handling code" is usually more verbose in
> FreeMarker.

I think FreeMarker is less verbose than XSLT, at least in the basic
cases... and then XSLT is specialized on transforming XML documents,
while FreeMarker isn't.

> Again, not a complain but an explanation why I think people have 
> problems with this area. I'm very happy FM is even able to handle XML 
> and I do appreciate it :).
>
> S!
> D.

-- 
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
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.