Forum Discussion

id-chalmers's avatar
10 years ago

Accessing inner text of freemarker xml response elements

I'm using the lithium rest API and having a problem accessing elements' contained text values in the XML response. I can get the @attributes values but trying to get the text value of the element returns a freemarker error.

 

Here's my code:

<#assign groups = rest("/categories/id/platinum_groups/groups/list").groups/>
${groups.@@markup}
<ul class="groups-list">
<#list groups.group as group>
<li><a href="${group.@view_href}">${group.default_role.short_title}</a></li>
</#list>
</ul>

 

Also: I can see from calling groups.@@markup that each group has an element called default_role which contains sub-elements including short_title. however when i call @@markup on the element it comes up empty. 

 

 for example ${group.default_role.@@markup} returns just <default_role href="/roles/id/863" type="role"></default_role>

 

Is there a different way to access the contained text for an element? The method shown in this post  seems like it's just calling it with dot syntax ie: ${recent.message.subject}

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)

    id-chalmers to debug this, you could go into Studio / API Browser and do:

     

    SELECT * FROM categories WHERE id = 'platinum_groups'

     

    And would see that the resutls is encapsulated (probably not the correct term) in 'items' and not 'group'.

     

    2015-04-14_0037.png

     

    So your code should be:

     

    <#assign groups = rest("/categories/id/platinum_groups/groups/list").groups/>
    ${groups.@@markup}
    <ul class="groups-list">
    <#list groups.items as group>
    <li><a href="${group.@view_href}">${group.default_role.short_title}</a></li>
    </#list>
    </ul>