Re: how to warn about missing xml node?
"Daniel Dekany (temporary acc!)" <[email protected]> Mon, 13 Oct 2003 23:01:03 +0200
| Newsgroups | gmane.comp.text.fmpp |
|---|---|
| Message-ID | <[email protected]> |
Monday, October 13, 2003, 12:29:41 PM, Ralf Hauser wrote:
> a <#macro of mine typically gets parameters of the kind
> pathFileBaseName=xml.site.files.thisFilename.@baseName
> out of
> <#assign xml = pp.loadData("xml", "site.xml")>
>
> if for some reason, the not thisFilename was forgotten in site.xml, I would
> like the macro to print
> what it got in the parameter literally.
>
> However, if I do
> <#if pathFileBaseName?has_content?string = "false">
Off-topic note: the above is a syntactical monster... it should be
simply:
<#if !pathFileBaseName?has_content>
or <#if pathFileBaseName?has_content == false> if you don't like "!"
> <@pp.warning message="pathFileBaseName ${pathFileBaseName} not found
> in \
site.xml" />>
> </#if>
>
> I still get
> [fmpp] Expecting a string, date or number here, Expression
> pathFileBaseName
> is instead a freemarker.ext.dom.NodeListModel
Of course...
> but I would like to see whether this is "thisFilename" or "thisFilename1" or
> "thisFilename2"
> how would one do that?
Er... IMO you can't. The problem is that here you should print the name
of the parent element ("thisFilename"), but since the resulting node-set
is empty, there is no node available that could you navigate backward.
You can't get the parent, as the are no children, so the track was lost.
So you should change the flow of the code a bit:
(Note however that it is actually a FreeMarker question, so feel free to
ask it on the FreeMarker list... not that I expect you get other answer,
but maybe Jonathan (the XML stuff author) has some innovative idea.)
<#local fileInfo = pathFileBaseName=xml.site.files.thisFilename>
<#if !fileInfo?has_content>
<@pp.warning message="Entry for file ${fileInfo?node_name} not
found in site.xml!" />
</#if>
<#local pathFileBaseName = fileInfo.@baseName>
--
Best regards,
Daniel Dekany
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php