include an image in an xml output.

matthew.wren's Avatar


08 Dec, 2014 03:53 PM

I'm working with our IT department with the creation of a new mobile application and I'm providing them with XML outputs of specific pages within our Royal News website. I've been able to create these easily enough but this particular case is slightly different and I'm not sure what I need to do.

We have index pages that list the article's in that particular week's issue. Here's the example of the second week of November

The idea is to have a featured image on this page for the app. I created a Data Definition that allows an image to be inserted but we only want the image to appear in an XML output. How would I go about that?

I've attached a screenshot of the index block (which pulls any article the index page shares) and the format is:

#set ( $PageItems = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[name != 'index']") )
#set ( $ListItems = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder[name != 'images']") )
#set ( $PageTitle = $_XPathTool.selectSingleNode($contentRoot, "//calling-page/system-page/display-name") )
## for folders
#if ( $ListItems )
    #foreach( $Item in $ListItems )
        #set ( $Issue = $Item.getChild('title').text )
        #set ( $ItemURL = $Item.getChild('link') )
            <a href="${ItemURL.value}">${Issue}</a>
## for pages
#if ( $PageItems )
    #foreach( $Page in $PageItems )
        #set ( $PageT = $Page.getChild('title').text )
        #set ( $PageURL = $Page.getChild('link') )
            <a href="${PageURL.value}">
#if ( $Imgs )
    #foreach ( $Img in $Imgs )
        #set ( $ImgName = $Img.getChild('name') )
        #set ( $ImgURL = $Img.getChild('link') )
            ##  $ImgURL.value<br/>
            #if ( $ImgName.value == 'cover.jpg' )
                <a href="${ItemURL.value}"><img src="${ImgURL.value}" alt="Cover"/></a>


Currently the XML output has only the index applied.

  1. 1 Posted by Lisa McWilliams on 10 Dec, 2014 02:30 AM

    Lisa McWilliams 's Avatar

    Hi Matthew,

    I'm not sure I understand the question. Which data definition did you attach the image chooser to? The index page or the article pages?

    Also what is $Imgs supposed to represent? A folder containing images or a group of images? In your request, it sounded like you wanted 1 image, but you are using a loop in your format, so it must be a group of images. Can you provide more details of where the images are coming from?



  2. 2 Posted by matthew.wren on 10 Dec, 2014 02:34 PM

    matthew.wren's Avatar

    Hi Lisa,

    I think that's just a coincidence that there's a commented-out section dealing with an image! Sorry I didn't even notice it. I haven't actually done anything with the script yet.

    Here's the entire Data Definition I created for these index pages:

      <asset type="file" identifier="featured-index-image" label="Featured image for Each Issue"/>

    I am just wondering how I can include that image into only the xml output

  3. 3 Posted by Lisa McWilliams on 10 Dec, 2014 05:17 PM

    Lisa McWilliams 's Avatar

    Thanks for clearing that up. There are two ways to accomplish your goals. One is to go to the block you are using to pull the articles and check the 'append calling page' box (if it isn't already selected). That will add the index page's data definition to your block and then you can access it normally via xpath like so:

        #set($page = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page") )
     #set($img = $XPathTool.selectSingleNode($page, "system-data-structure/featured-index-image))

    Then to add the image you just output the link

     #set($link = $img.getChild("link").value)
     <img src="${link}" />

    The other option is to use the locator tool.

    #set($img = $currentPage.getStructuredDataNode("featured-index-image"))
     #set($link = $
        <img src="${link}" />
  4. 4 Posted by matthew.wren on 11 Dec, 2014 07:21 PM

    matthew.wren's Avatar

    I added those snippets into my format but I'm not seeing the node appear in the xml page

    Am I missing something?

  5. 5 Posted by Lisa McWilliams on 11 Dec, 2014 08:24 PM

    Lisa McWilliams 's Avatar

    Hi Matthew,

    It looks like your index block being applied to the format probably does
    not have 'Render page XML inline only for current page' selected. I've
    attached a copy of the index block, you need to select the Render page XML
    inline only for current page option next to 'Page XML'.

    I've attached an image copy of a block with that option selected. You don't
    need to change the other areas of your block, only the area 'Page XML'. I
    just included a picture of the whole thing so you would know what I was
    showing you.

    [image: Inline image 1]

    Lisa McWilliams
    Services Project Manager

  6. 6 Posted by matthew.wren on 11 Dec, 2014 08:29 PM

    matthew.wren's Avatar

    that worked! Excellent thank you so much! I think that's all I need for now but thanks again!

  7. 7 Posted by Lisa McWilliams on 11 Dec, 2014 08:31 PM

    Lisa McWilliams 's Avatar

    You're welcome :) I'm going to close this now and if you have different issue you can open a new discussion.

  8. Lisa McWilliams closed this discussion on 11 Dec, 2014 08:31 PM.

  9. matthew.wren re-opened this discussion on 12 Dec, 2014 08:59 PM

  10. 8 Posted by matthew.wren on 12 Dec, 2014 08:59 PM

    matthew.wren's Avatar

    Okay so there's been a misunderstanding on my part. We aren't looking to have a image picker from the index page included in the XML, rather, each article has their own featured image and that needs to be included with their corresponding node.

    So if you look at this page again, you'll see the various articles include within that week's issue. Is there a way I can include the image from each article into that xml output?

  11. 9 Posted by Lisa McWilliams on 12 Dec, 2014 09:14 PM

    Lisa McWilliams 's Avatar

    Hi Matt,

    To get them all to display, just change that same block. Instead of
    selecting Render page XML inline only for current page' for the Page XML
    option, instead choose Render page XML inline. This will display the data
    definition for all of the articles and will show the article's images.

    Let me know if that's what you are looking for,


    Lisa McWilliams
    Services Project Manager

  12. 10 Posted by matthew.wren on 12 Dec, 2014 09:30 PM

    matthew.wren's Avatar

    I must not have the right option selected because now it only shows one article but it does show all of its content!

    I'll attach the image to of the block again, maybe I'm missing something else.

  13. 11 Posted by Lisa McWilliams on 12 Dec, 2014 09:45 PM

    Lisa McWilliams 's Avatar

    It looks like the issue is that one of your articles has code that is not
    xml compliant. Because there is an error, the rest of the articles are not
    displaying. The only solution here is to go into that article (and perhaps
    all of your articles) and check the wysiwyg content. The error message
    suggests maybe there is a fb like button in the articles?

    I'm thinking the 'tidy html' checkbox option for your pages is unchecked,
    so that you can add whatever code you want without it getting stripped by
    the editor. But this can lead to non compliant code that the xml cannot
    parse. It's only an issue if you want to output xml like you are doing now.

    Checking all of the articles can be rather tedious, can I ask why you are
    trying to get this xml block to display? What are you using it for?



    Lisa McWilliams
    Services Project Manager

  14. 12 Posted by matthew.wren on 15 Dec, 2014 02:02 PM

    matthew.wren's Avatar

    I'm providing content to our IT department so they can include the issues in our new mobile app they are working on along with an outside developer.

    We are trying to order the articles to how they are listed on the main page every week (featured release & 3 other main releases). The main index page, however, changes week-to-week so there isn't a way to reflect this in the app. They asked me to provide them with an XML output of the release page and have it ordered manually with the featured article as number 1 and the other three after that.

    The content seems to pull just fine but those 4 articles always have an image associated with them and we want those included alongside the weekly article listing. We are just trying to avoid adding more steps along with our normal workflow for Royal News.

  15. 13 Posted by Lisa McWilliams on 15 Dec, 2014 02:15 PM

    Lisa McWilliams 's Avatar

    Hi Matthew,

    Thanks for explaining. What do you mean by "the content pulls fine"? From
    what I saw in your screenshot, the xml will not display because the
    articles contain content that is not xml compliant. It looked like maybe a
    facebook share button/code or something is in the wysiwyg. You can copy the
    wysiwyg content and run it through an xml validator tool to verify. But in
    order to get the articles to show up the way you want them, the content
    will need to be compliant.

    Otherwise you can create a format and build your xml document there. That
    way you can wrap the content in : $_EscapeTool.xml()

    Lisa McWilliams
    Services Project Manager

  16. 14 Posted by matthew.wren on 15 Dec, 2014 02:21 PM

    matthew.wren's Avatar

    I meant it pulled fine previously when it was just the article links without the page's content.

    How would I create a format to create this XML document? That seems like the best route in this case because I'm not sure what the content will contain weekly.

  17. Support Staff 15 Posted by Tim on 26 Feb, 2015 04:27 PM

    Tim's Avatar

    Hi Matthew,

    Just wanted to check in here and see if you were able to get things working on your end. Let us know how things are going.


  18. 16 Posted by matthew.wren on 03 Mar, 2015 02:47 PM

    matthew.wren's Avatar

    Hey Tim,

    Yes I believe I have! thank you very much!

  19. Support Staff 17 Posted by Tim on 03 Mar, 2015 02:51 PM

    Tim's Avatar

    Glad to hear it! Thanks for the update, Matthew. Take care!

  20. Tim closed this discussion on 03 Mar, 2015 02:51 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac