Re: How to still get the Key-Value pair even though Value in the Hash is null

Daniel Dekany <[email protected]> Tue, 16 Sep 2014 02:19:22 +0200
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
XML DOM nodes aren't regular hashes. They return a 0 length sequence
of nodes when there's no match. This is need for chaining
(foo.bar.baaz) and #list-ing to work regardless the number of hits (0,
1 or multiple). So, quoted from the Manual
(http://freemarker.org/docs/xgui_imperative_learn.html):

  It is important to realize the consequence that, for example, if
  book has no chapter-s then book.chapter is an empty sequence, so
  doc.book.chapter?? will not be false, it will be always true!
  Similarly, doc.book.somethingTotallyNonsense?? will not be false
  either. To check if there was no children found, use
  doc.book.chapter[0]?? (or doc.book.chapter?size == 0). Of course you
  can use similarly all the missing value handler operators (e.g.
  doc.book.author[0]!"Anonymous"), just don't forget that [0].


Tuesday, September 16, 2014, 12:08:49 AM, ven12344 wrote:

> Hi,
>
> I am getting the nodes from an xml file, like this
>
> <#local titles = doc[XPATH] >
>
> lets say for one element, this xpath does not exist. What I need to do is
> that I need to replace the "null" with "empty".
>
> But I am not even getting this key-value pair in the local variable
> "titles", like Java Hash concept, if the value of the element in Hash is
> null then entire element becomes null, right.
>
> I am looking solution in XPath, to check if the xpath exists then get the
> value of it otherwise put the value as "empty". But could not able to get
> the solution.
>
> If anybody knows how to do it in Freemarker or XPath, I will appreciate the
> help.
>
> Thanks.
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/How-to-still-get-the-Key-Value-pair-even-though-Value-in-the-Hash-is-null-tp4655272.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Want excitement?
> Manually upgrade your production database.
> When you want reliability, choose Perforce
> Perforce version control. Predictably reliable.
> http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

-- 
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce.
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk