Velocity Script and Namespaces
We are attempting to read in an Atom feed using a feed block in Cascade, but are having trouble parsing it using a Velocity script. We are certain it is a namespace issue, having encountered similar difficulties using XSLT. We know how to declare a namespace in an XSLT script, and in fact have successfully parsed the same feed with XSLT, but we'd love to know how to do this with Velocity. So how and where does one declare the namespace in a Velocity script?
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Ross on 22 Nov, 2010 08:45 PM
What errors are you encountering?
Velocity doesn't have any implicit problem with namespaces, as the source XML is read directly to a JDOM Document object available as
$contentRoot.It may help in testing to try
$contentRoot.namespace.prefixand$contentRoot.namespace.URI.You can also check for a particular namespace prefix:
$contentRoot.getNamespace('atom')3 Posted by erikg on 22 Nov, 2010 09:51 PM
I don't get an error so much as nothing at all. If I make a static copy of the feed, remove the namespace reference (just changing the beginning
<feed xmlns="http://www.w3.org/2005/Atom">to just<feed>, and have my script parse that things are fine. With the namespace reference, nothing is returned. We do have control over the blog software and well and tried altering the content of the feed. Once again, remove the namespace reference and it is fine, keep it and nothing is returned. Unfortunately we'd like to keep the default setting for the blog software if possible, so that isn't a good option for us.Referencing your tests,
$contentRoot.namespace.URIproduces the properhttp://www.w3.org/2005/Atom, but$contentRoot.namespace.prefixreturns nothing.$contentRoot.getNamespace('atom')returns nothing as well.The feed can be seen at http://blogs.reed.edu/reed_magazine/atom.xml. This is the default feed produced by default by Moveable Type, which is blogging software similar to Word Press. The blog itself is a site we're starting to develop, so it contains only test data at this time. If you have trouble seeing it let me know.
4 Posted by erikg on 23 Nov, 2010 05:03 PM
I thought I'd follow up with our attempts to get the script to work. Based on the working XSLT script, we tried this:
This results in the following error (which is better than getting nothing) in our log file:
Perhaps you can tell me what's wrong with the script? I've never seen a working example of a Velocity script for an atom feed, so it is likely I missed something.
5 Posted by Joel on 01 Dec, 2010 08:40 PM
Erik,
Thanks for bringing this to our attention as we have identified it as a bug. Please monitor CSI-98 for implementation progress.
Thanks!
Ross closed this discussion on 04 Mar, 2011 06:52 PM.