Re: NodeModels from namespaced DOM Elements
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Monday, September 12, 2011, 7:15:22 PM, Tom Fennelly wrote:
> Hi guys.
>
> Do you need to do something special to use NodeModels build from a
> namespaced DOM Element? Attached please find a test that works when
> the XML is not namespaced, but fails when it is namespaced.
In XML, an element type is identified by its namespace URI and its
local name. The actual prefix (or the lack of it) is irrelevant, and
so is that you don't use any prefix in either XML files. One still
have "item" with no namespace, and the other has "item" in the
"http://acme.com/ns" namespace. Since in the template you ask for
elements with no namespace, nothing will match in the second XML.
In your case, to precess the XML that uses namespace, you have to
start the template with:
<#ftl ns_prefixes={"D": "http://acme.com/ns"}>.
For more details, see:
http://freemarker.org/docs/xgui_imperative_learn.html#autoid_73
>
> The FreeMarker error I get is....
>
> 18:09:27,170 ERROR [main][runtime]
> Error on line 1, column 3 in free-marker-template
> Expecting a string, date or number here, Expression item.nachname is
> instead a freemarker.ext.dom.NodeListModel
> The problematic instruction:
> ----------
==>> ${item.nachname} [on line 1, column 1 in free-marker-template]
> ----------
>
> Java backtrace for programmers:
> ----------
> freemarker.core.NonStringException: Error on line 1, column 3 in
> free-marker-template
> Expecting a string, date or number here, Expression item.nachname is
> instead a freemarker.ext.dom.NodeListModel
> at freemarker.core.Expression.getStringValue(Expression.java:126)
> at freemarker.core.Expression.getStringValue(Expression.java:93)
> at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
> at freemarker.core.Environment.visit(Environment.java:209)
> at freemarker.core.MixedContent.accept(MixedContent.java:92)
> at freemarker.core.Environment.visit(Environment.java:209)
> at freemarker.core.Environment.process(Environment.java:189)
> at freemarker.template.Template.process(Template.java:237)
> at
> org.milyn.templating.freemarker.FreeMarkerNodeModelTest.applyTemplate(FreeMarkerNodeModelTest.java:53)
> at
> org.milyn.templating.freemarker.FreeMarkerNodeModelTest.test_with_namespace(FreeMarkerNodeModelTest.java:41)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at junit.framework.TestCase.runTest(TestCase.java:168)
> at junit.framework.TestCase.runBare(TestCase.java:134)
> at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)
> at junit.framework.TestResult.run(TestResult.java:113)
> at junit.framework.TestCase.run(TestCase.java:124)
> at junit.textui.TestRunner.doRun(TestRunner.java:116)
> at
> com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
> at junit.textui.TestRunner.doRun(TestRunner.java:109)
> at
> com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
> at
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
> at
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops? How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/