Re: Beginner question: Accessing XML-Attributes via Template?
Daniel López <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
That Exception: "Expecting...is instead a
freemarker.ext.dom.NodeListModel" is the most common one when processing
XML with FreeMarker. If you come from an XSLT background, it takes a
while to get used to it but FreeMarker is not as lenient as XSLT is,
meaning that if a node does not exist, in XSLT usually "nothing happens"
whereas in FreeMarker, an error is produced.
And as Daniel Dekany indicated, this is usually the error that is
produced when your "XPath" does not match a Node. Instead of returning
"nothing", FreeMarker returns an empty list of nodes, hence the error
message. Given the XML, it looks as if it should match correctly one
node, but given that there are namespaces in the mix, I'm not that sure
as I have not played with "namespaced" XML with FreeMarker.
Good luck!
D.
Daniel Dekany escribió:
> Tuesday, March 24, 2009, 12:47:58 AM, Tarik M. wrote:
>> Hello,
>>
>> thanks a lot for the example. I read the tutorial several times, but I
>> wasn't able to navigate through my XML-Document hierarchy. Whatever I've
>> tried I got the following Exception:
>>
>> Expecting a string, date or number here, Expression
>> bdd.bisgridWorkflow.wsbpelEngineInformation.@wsbpelProcess is instead a
>> freemarker.ext.dom.NodeListModel
>
> The error message basically means that the result of your XML query
> contains not exactly one node. So either you have 0 matching node, or
> multiple matching nodes (try ${yourQuery?size} to find out which). In
> those cases a the resulting node list can't be automatically treated
> as a scalar, hence the cryptic error message.
>
>> In the template I defined:
>> <process
>> name="${doc.bWorkflow.wsbpelEngineInformation.@wsbpelProcess}">
>>
>> Here is the XML part:
>> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>> <bdd:wsbpelEngineInformation wsbpelProcess="..."
>> wsbpelProcesslocation="...">
>> ....
>>
>> I thought that this is the way to navigate through the DOM-Tree, because the
>> tutorial examples show the same. Does anybody know what's wrong in my
>> example?
>>
>> Thanks in advance.
>> Tarik
>>
>>
>>
>> Daniel Lopez-3 wrote:
>>> Hi,
>>>
>>> The first place you can go to see how to handle XML content from a
>>> FreeMarker template is the manual itself ->
>>> Part III. XML Processing Guide:
>>> http://freemarker.sourceforge.net/docs/xgui.html
>>>
>>> Then you can see a working example like the one we have through FishEye:
>>> A sample XML document:
>>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/xml/showItems.xml?r=1.2
>>> The FreeMarker template:
>>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/templates/item.ftl?r=1.2
>>> The resulting HTML:
>>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/showItems.html?r=1.4
>>>
>>> S!
>>> D.
>>>
>>> Tarik Mustafic escribió:
>>>> Hello everybody,
>>>>
>>>> I'm trying to parse a XML-Document with Freemarker and to merge the
>>>> model with a template, especially accessing the XML-Attributes from the
>>>> model. I have done the following:
>>>>
>>>> --------------------- code
>>>> Map<String, Object> root = new HashMap<String, Object>();
>>>> root.put("doc", freemarker.ext.dom.NodeModel.parse(new
>>>> File("file.xml")));
>>>> --------------------- code
>>>>
>>>> The XML-document looks like as follows:
>>>>
>>>> --------------------- code
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>>>> <bdd:wsbpelEngineInformation wsbpelProcess="..."
>>>> wsbpelProcesslocation="...">
>>>> <bdd:versioning version="..."/>
>>>> <bdd:persistence storePersistent="..."/>
>>>> <bdd:partnerLinks>
>>>> <bdd:partnerLink name="...">
>>>> <bdd:myRole>
>>>> <bdd:endpointReference
>>>> serviceName="..."
>>>> servicePort="..."
>>>> binding="..."
>>>> xmlns:pal="..."/>
>>>> </bdd:myRole>
>>>> </bdd:partnerLink>
>>>> <bdd:partnerLink name="...">
>>>> <bdd:partnerRole bdd:serviceType="..."
>>>> bdd:serviceCall="..."/>
>>>> </bdd:partnerLink>
>>>> </bdd:partnerLinks>
>>>> <bdd:extensions/>
>>>> <bdd:references>
>>>> <bdd:reference location="..." referenceGroup="..."
>>>> namespace="..."/>
>>>> <bdd:reference location="..." referenceGroup="..."
>>>> namespace="..."/>
>>>> </bdd:references>
>>>> </bdd:wsbpelEngineInformation>
>>>> </bdd:bWorkflow>
>>>> --------------------- code
>>>>
>>>> Now my question: How can I access the XML-Attribute elements in the
>>>> Template? For example how to get the version-Attribute of the
>>>> versioning-Element etc?
>>>>
>>>> Thanks in advance.
>>>>
>>>> Kind regards.
>>>> Tarik
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user