Format for XML File

Graham Lewis's Avatar

Graham Lewis

27 Feb, 2015 09:58 PM

I have imported this file into Cascade and am wanting to make a velocity format that reads it and displays content. I am unsure how to begin with my variables. I am wanting to do something like this...

#set ($classes = $_XPathTool.selectNodes($contentRoot, "//system-block/system-data-structure"))

#foreach($class in $classes)
#set ( $name = $class.getChild("CRSE_NUMB").value)
#set ( $number = $class.getChild("CRSE_TITLE").value)
#set ( $number = $class.getChild("CRSE_DESC").value)
  1. 1 Posted by Ryan Griffith on 02 Mar, 2015 08:38 PM

    Ryan Griffith's Avatar

    Hi Graham,

    Was this XML file created as an XML Block by chance? If so, are you applying it directly to a region or using a Block chooser within a Data Definition?

    The following may change based on your answer, but here's my initial thought as to what should work:

    #set ($classes = $_XPathTool.selectNodes($contentRoot, "//RESULTS/ROW"))
    #if ($classes.size() > 0)
        #foreach ($class in $classes)
          #set ( $number = $_XPathTool.selectSingleNode($class, "COLUMN[@NAME='CRSE_NUMB']").value)
          #set ( $title = $_XPathTool.selectSingleNode($class, "COLUMN[@NAME='CRSE_TITLE']").value)
          #set ( $description = $_XPathTool.selectSingleNode($class, "COLUMN[@NAME='CRSE_DESC']").value)
    
          <p>Number: $_EscapeTool.xml($number)<br />
          Title: $_EscapeTool.xml($title)<br />
          Description: $_EscapeTool.xml($description)</p>
        #end
    #end
    

    Note: because you have multiple COLUMN elements within each ROW, using the XPath Tool would be your best best so you can filter by the @NAME attribute.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Graham Lewis on 02 Mar, 2015 08:55 PM

    Graham Lewis's Avatar

    You, sir, are the bomb.com haha

    That worked perfectly.

    Graham Lewis
    Webmaster
    Jacksonville State University

    256.782.5331
    www.jsu.edu

  3. 3 Posted by Ryan Griffith on 02 Mar, 2015 09:03 PM

    Ryan Griffith's Avatar

    Thank you for following up, Graham. I am glad to hear the proposed Velocity code did the trick for you.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  4. Ryan Griffith closed this discussion on 02 Mar, 2015 09:03 PM.

  5. Graham Lewis re-opened this discussion on 02 Mar, 2015 09:04 PM

  6. 4 Posted by Graham Lewis on 02 Mar, 2015 09:04 PM

    Graham Lewis's Avatar

    Sounds good - thanks!

    Graham Lewis
    Webmaster
    Jacksonville State University

    256.782.5331
    www.jsu.edu

  7. Ryan Griffith closed this discussion on 02 Mar, 2015 09:19 PM.

  8. Graham Lewis re-opened this discussion on 03 Mar, 2015 04:12 PM

  9. 5 Posted by Graham Lewis on 03 Mar, 2015 04:12 PM

    Graham Lewis's Avatar

    If I wanted to display text that is between ( ), how would I do that? I would just want to display Printmaking.

    <COLUMN NAME="PROGRAM_DESC"> 
    <![CDATA[Art (Printmaking), Bachelor of Arts]]> 
    </COLUMN>
    

    Graham Lewis
    Webmaster
    Jacksonville State University

    256.782.5331
    www.jsu.edu

  10. 6 Posted by Ryan Griffith on 03 Mar, 2015 07:22 PM

    Ryan Griffith's Avatar

    Hi Graham,

    There are a couple of ways I can think of to accomplish this, both of which assume you just want the text within the first matching parentheses.

    When you have a moment, try the following and let me know how it works out:

    $str.split("[\(\)]")[1]
    $str.substring($_MathTool.add($str.indexOf("("),1),$str.indexOf(")"))
    

    The first splits by the ( and ) and will give you the first text that appeared within the parentheses. The second will locate the indexes of the first ( and ) and perform a substring to get the text.

    Please let me know if you have any questions.

    Thanks!

  11. 7 Posted by Graham Lewis on 04 Mar, 2015 02:43 PM

    Graham Lewis's Avatar

    Ryan,

    That worked. An issue I am running in to is I have two blocks being called on the same page, but in two different DD groups. One is for "programs" and one is for "courses" - they both have the same structure //results/rows and I am thinking they are getting mixed up - two of my tests works, but one doesn't. On the one that doesn't - if the programs xml displays correctly, the courses doesn't and if the courses work the programs don't. lol.

    Graham Lewis
    Webmaster
    Jacksonville State University

    256.782.5331
    www.jsu.edu

  12. 8 Posted by Ryan Griffith on 04 Mar, 2015 03:15 PM

    Ryan Griffith's Avatar

    Thank you for following up, Graham. I am glad to hear the my suggestions worked.

    An issue I am running in to is I have two blocks being called on the same page, but in two different DD groups

    In this case, I would suggest being more specific with the XPath that is used to grab the classes to target the correct Block. Specifically, using //RESULT will get all RESULT elements at any level.

    Please let me know if you have any questions.

    Thanks!

  13. 9 Posted by Graham Lewis on 04 Mar, 2015 03:23 PM

    Graham Lewis's Avatar

    So maybe - #set ($data = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/degrees/results/row")) ?

    Graham Lewis
    Webmaster
    Jacksonville State University

    256.782.5331
    www.jsu.edu

  14. 10 Posted by Ryan Griffith on 04 Mar, 2015 03:35 PM

    Ryan Griffith's Avatar

    Is degrees a block chooser? If so, I think it would be more like:

    /system-index-block/calling-page/system-page/system-data-structure/degrees/content/RESULTS/ROW
    

    Note: I am pretty sure the element name is case sensitive, so if RESULTS and ROW are all caps in the XML Block, you'll want to repeat that in your XPath.

    Please let me know if you have any questions.

    Thanks!

  15. Ryan Griffith closed this discussion on 11 Mar, 2015 08:33 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