Can't get the page elements

webadmin's Avatar

webadmin

19 Jun, 2015 08:04 PM

I'm sure I'm doing something stupid here, but I can't get the page elements for the life of me. I have a very simple XML index of a folder with a few pages in it. The highest level tag is "system-index-block", with "system-page" elements underneath it (they're the next level down). Why does this code below return nothing? I've tried the selectNodes line with a slash before system-page, and without. Neither return anything. Can you tell me what I'm doing wrong, and why it doesn't work? Thanks.

## Abstract out the "system-index-block" node
#set ($sib = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block"))

## Gather "system-page" nodes
#set ($items = $_XPathTool.selectNodes($sib, "/system-page"))

Item size is $items.value <br />

## Make the menu
#if ($items.size > 0)
    ## Loop through pages
    #foreach ($item in $items)
        $item.getAttribute("name") <br />
    #end    
#end
  1. 1 Posted by Wing Ming Chan on 19 Jun, 2015 11:10 PM

    Wing Ming Chan's Avatar

    Hi,

    Try removing the slash right before 'system-page'.

    Wing

  2. 2 Posted by Ryan Griffith on 22 Jun, 2015 12:16 PM

    Ryan Griffith's Avatar

    Also, if you are attempting to get the system name of the pages, you will want to change the following:

    $item.getAttribute("name")
    

    to:

    $item.getChild("name").value
    

    Please let me know if you have any questions.

    Thanks!

  3. 3 Posted by webadmin on 22 Jun, 2015 01:45 PM

    webadmin's Avatar

    Like I said, I already tried it without the slash, and it didn't work that way either. I just tried it again to verify. As for the getChild part, the $items variable isn't loading at all, so it wouldn't matter about that. I'm attaching the XML I'm trying to read. Maybe there's something weird about it.

  4. 4 Posted by Ryan Griffith on 22 Jun, 2015 02:41 PM

    Ryan Griffith's Avatar

    Just noticed your #if statement is incorrect. When you have a moment, try changing it to the following:

    #if ($items.size() > 0)
    

    So, with all of the changes:

    ## Abstract out the "system-index-block" node
    #set ($sib = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block"))
    
    ## Gather "system-page" nodes
    #set ($items = $_XPathTool.selectNodes($sib, "system-page"))
    
    Item size is $items.value <br />
    
    ## Make the menu
    #if ($items.size() > 0)
        ## Loop through pages
        #foreach ($item in $items)
            $item.getChild("name").value <br />
        #end    
    #end
    

    Please let me know if you have any questions.

    Thanks!

  5. 5 Posted by webadmin on 22 Jun, 2015 02:53 PM

    webadmin's Avatar

    That did make it loop correctly, but why does $items.value not show anything? Isn't that supposed to output the entirety of the variable? If $items exists, shouldn't I get a big list of text out of it?

  6. 6 Posted by Ryan Griffith on 22 Jun, 2015 05:28 PM

    Ryan Griffith's Avatar

    Thank you for following up, I am glad to hear the adjustment did the trick.

    why does $items.value not show anything? Isn't that supposed to output the entirety of the variable? If $items exists, shouldn't I get a big list of text out of it?

    .value is shorthand for a getValue() method on the object you are invoking it on, which in this case would most likely be a JDOM Element. If you want to dump the contents of the element, I would recommend something more like:

    $_SerializerTool.serialize($items, false)
    

    Please let me know if you have any questions.

    Thanks!

  7. Ryan Griffith closed this discussion on 30 Jun, 2015 07:09 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? 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

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM