Not sure how to read part of my XML feed.
I'm getting an XML feed from a wordpress site we own, and I'm having a bit of trouble. We're using the "featured image" they have, and I'm trying to get that link. I'm just not sure how to request it from the feed, since it displays a bit oddly. Here's the code:
<media:thumbnail url="https://nobtsgatekeeper.files.wordpress.com/2015/05/sendnola.jpg?w=150"/>
<media:content medium="image" url="https://nobtsgatekeeper.files.wordpress.com/2015/05/sendnola.jpg?w=150">
<media:title type="html">sendnola</media:title>
</media:content>
<media:content medium="image" url="https://0.gravatar.com/avatar/6772422f873982faaf6b86c97e75d1e5?s=96&d=identicon&r=G">
<media:title type="html">nobtslive</media:title>
</media:content>
As an aside, I'm having a bit of trouble getting velocity script to remove an ampersand. I use this:
set ($thePageTitle = $thePageTitle.replace("&", "&"))
But the system still balks at the existence of the ampersand. What's the trick to make it remove the ampersand without freaking out?
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 webadmin on 11 May, 2015 03:07 PM
Sorry, forgot to mention, I'd like to be able to read all three of those and be able to tell the difference between them. Thanks.
2 Posted by Ryan Griffith on 11 May, 2015 06:40 PM
Hi,
It sounds like you are having issues with dealing with the
media
namespace used by the feed. There are a couple of ways you can go about accessing those elements:local-name
(ie without the namespace) and then output the attribute value. For example:I believe
String.replace
will only replace the first occurrence. Instead try something like the following:The regex should also ensure you are not double encoding ampersands.
Please let me know if you have any questions.
Thanks!
3 Posted by webadmin on 11 May, 2015 08:13 PM
That's still not working on the ampersand replacement. I get this error when I have an ampersand in the display name and title of a page:
An error occurred: Could not transform with Script format "_site/transformations/Breadcrumbs": Error on line 13: The entity name must immediately follow the '&' in the entity reference.
Attached is my transformation. I tried stripping the ampersands out of every time I read the name, but it's still not working.
4 Posted by webadmin on 11 May, 2015 08:52 PM
I tried what you gave me to read the media stuff, and I'm still having trouble. I changed it slightly, because I'm looping over an item that has media tags I listed earlier. I didn't want the // on it, because that makes it give me every media tag in the page. I've changed it to this:
This does appear to give me all the media tags of type content in the item. What I don't quite get is why I can't type this and have it work:
or
From the documentation I've seen, that ought to give me any tag named "media". Instead, it gives me nothing. Also, I can't seem to differentiate between the two. When I view the value of each node in the $images node, I see the text between the tags inside it ("nobtslive" and "sendnola", in this example). However, I can't do any tests on it. When I try to see if the value is equal to "nobtslive", it comes back false no matter what.
Also, how do I read the URL out of the tag? I can't figure out the code to grab it.
5 Posted by Ryan Griffith on 12 May, 2015 03:21 PM
Hi,
Curious, but have you tried using the Escape Tool instead to escape entities? Perhaps try adjusting the end of your
GetPageName
macro to the following:Note: we're setting the variable to the
.value
now instead of the Element itself, so you will want to adjust references later in your script to no longer use$thePageTitle.value
.The reason your XPath queries won't work is because
media
is a namespace, not a node name.Ideally, you would use
media:content
for the node name; however, this will not work because there is currently no way to register custom namespaces for the XPath Tool to use (similar to what you can do with XSLT). Instead, you would receive an error stating you are using an unregistered namespace.Your best bet would be to check the value of the
url
attribute as follows:Please let me know if you have any questions.
Thanks!
6 Posted by webadmin on 12 May, 2015 09:43 PM
I'm still getting the same problem with the ampersands, but the URL request worked.
7 Posted by Ryan Griffith on 13 May, 2015 12:54 PM
Thank you for following up. I am glad to hear you were able to access the URL attribute.
Did you have a chance to try out the Escape Tool? If so, and that still doesn't work, it sounds like that
&
in the URL might be double-encoded. Perhaps try the following to see if it helps:Please let me know if you have any questions.
Thanks!
8 Posted by webadmin on 13 May, 2015 01:38 PM
Still the same problem. This is the error I get:
An error occurred: Could not transform with Script format "_site/transformations/Breadcrumbs": Error on line 13: The entity name must immediately follow the '&' in the entity reference.
The problem is, there isn't anything on line 13 that should be throwing this, as far as I can see. I'm attaching the script I'm using. Line 13 is a blank line in my code.
9 Posted by Ryan Griffith on 13 May, 2015 03:30 PM
Thank you for testing.
Curious, but I noticed the following line appears to be incorrect:
Perhaps this regex might still work. Let's try correcting this to see if you still get the error:
This error is referring to the transformed content and not the Format itself. In this case, the line numbers won't line up to what you see in the code editor.
Please let me know if you have any questions.
Thanks!
10 Posted by webadmin on 13 May, 2015 04:18 PM
Same issue. As for that line of code with the error, I had it commented out for a while now. I assume that wouldn't affect anything once it's commented, right?
Is there any way to force Cascade to process the page anyway? I feel like I could fix this if I could figure out where it's seeing an ampersand. The display name is the one with the ampersand in it. From the code, it looks like no matter where the ampersand comes from, it should be cleared out by the last line of the code in the GetPageName macro. It shouldn't be throwing an error just by having an ampersand in a variable, should it?
11 Posted by Ryan Griffith on 13 May, 2015 04:50 PM
Bummer, thank you for trying anyway.
Correct, it will not be executed as long as you have the line commented out.
Perhaps try surrounding the entire content with a CDATA tag (
<![CDATA[ ... ]]>
) to see if you can at least render the invalid XML and see the output.Please let me know if you have any questions.
Thanks!
Support Staff 12 Posted by Tim on 17 Jun, 2015 01:53 PM
Hi,
Just wanted to check in to see if you saw Ryan's last comment. Let us know if you need more help.
Thanks
Tim closed this discussion on 30 Jun, 2015 06:43 PM.