external xml feed with multiple elements
I have an external xml feed that looks like this:
<Room property_id="1" room_id="19" room_name="BTC Conf Rm 103">
<booking event_id="32">
<Start_Time>3/28/2016 8:00:00 AM</Start_Time>
<End_Time>3/28/2016 5:00:00 PM</End_Time>
<Setup_Time>3/28/2016 7:30:00 AM</Setup_Time>
<Break_Down_Time>3/28/2016 5:30:00 PM</Break_Down_Time>
<Host>HUMAN RESOURCES</Host>
<Name_Of_Meeting>GENERAL ORIENTATION</Name_Of_Meeting>
</booking>
</Room>
I need to be able to access the individual elements in the Room tag: room_id and room_name.
I'm not sure how to define these in velocity. Any
suggestions?
Thanks,
Lauren
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
1 Posted by Ryan Griffith on 28 Mar, 2016 07:58 PM
Hi Lauren,
When you obtain the Room element, you can access the element's attributes using
$roomElement.getAttribute("room_id").value
.Please let me know if you have any questions.
Thanks!
2 Posted by lauren.fraser on 28 Mar, 2016 09:11 PM
Ryan,
I’m not sure what I’m doing wrong. I’m not getting any errors and not getting any content output:
#set ($feed = $_XPathTool.selectSingleNode($contentRoot, "/Rooms") )
#set ($events = $feed.getChild("Room"))
#set ($bookings = $events.getChild("booking"))
#foreach
($booking in $bookings)
#set ($startTime = $booking.getChild("Start_Time"))
#set ($endTime = $booking.getChild("End_Time").value)
#set ($host = $boooking.getChild("Host").value)
#set ($meetingName = $booking.getChild("Name_Of_Meeting").value)
#set ($roomID = $booking.getAttribute("room_id").value)
#set ($roomName = $booking.getAttribute("room_name").value)
<p> $_EscapeTool.xml($startTime.value)</p>
#end
3 Posted by Ryan Griffith on 29 Mar, 2016 12:08 PM
Hi Lauren,
Your
$feed
variable will already be an array of Room elements, so you can remove the next line. I would adjust to the following:Note: this assumes the XML structure you provided in your original comment. If you do happen to have that additional Rooms element, I would suggest two loops for both the rooms and their bookings.
Please let me know if you have any questions.
Thanks!
4 Posted by lauren.fraser on 29 Mar, 2016 03:32 PM
Ryan,
The xml structure should stay the same. I tried this xml and I'm still not getting any values.
5 Posted by Ryan Griffith on 29 Mar, 2016 06:19 PM
Lauren,
To confirm, will you always have a single Room with multiple booking elements? If so, perhaps the XPath on the first line is incorrect depending on how you are applying it to the format.
When you have a moment, try changing:
to:
Please let me know if you have any questions.
Thanks!
6 Posted by lauren.fraser on 29 Mar, 2016 07:29 PM
Ryan,
Same result: No errors, no data.
7 Posted by Ryan Griffith on 29 Mar, 2016 07:43 PM
Thank you for trying, Lauren.
When you have a moment, please paste or attach sample XML that you are applying to this format so I can take a closer look.
Please let me know if you have any questions.
Thanks!
8 Posted by Wing Ming Chan on 29 Mar, 2016 07:47 PM
Wing
9 Posted by Ryan Griffith on 29 Mar, 2016 07:55 PM
Thanks for chiming in Wing.
This will depend on how the XML is being applied to the Format (i.e. direct region assignment or an Index Block).
10 Posted by lauren.fraser on 29 Mar, 2016 07:57 PM
Here it is:
11 Posted by lauren.fraser on 29 Mar, 2016 07:58 PM
Ryan, I have this set up in a feed block. My plan was to apply that feed block to the content region and apply the format. I did try Wing's code, with the same result: no error, no data.
12 Posted by Ryan Griffith on 29 Mar, 2016 08:07 PM
Hi Lauren,
I suspected there may have been a discrepancy with the XML. When you have a moment, let's try the following:
Please let me know if you have any questions.
Thanks!
13 Posted by lauren.fraser on 29 Mar, 2016 08:14 PM
Ryan,
That worked. I’ve got some more sorting, etc to work on, but now I’m on the right track. Thanks for all the help!
14 Posted by Ryan Griffith on 29 Mar, 2016 08:16 PM
Not a problem at all, Lauren. Glad to hear the latest changes did the trick.
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!
Ryan Griffith closed this discussion on 29 Mar, 2016 08:16 PM.