tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/11937-not-sure-how-to-read-part-of-my-xml-feedCascade CMS: Discussion 2015-06-30T18:43:46Ztag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-11T15:07:25Z2015-05-11T15:07:25ZNot sure how to read part of my XML feed.<div><p>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.</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-11T18:40:19Z2015-05-11T18:40:19ZNot sure how to read part of my XML feed.<div><p>Hi,</p>
<p>It sounds like you are having issues with dealing with the
<code>media</code> namespace used by the feed. There are a couple
of ways you can go about accessing those elements:</p>
<ul>
<li>Loop over all of the children, check the name and then output
the attribute value</li>
<li>Use XPath to get the element by it's <code>local-name</code>
(ie without the namespace) and then output the attribute value. For
example:</li>
</ul>
<pre>
<code>#set ($images = $_XPathTool.selectNodes($contentRoot, "//*[local-name() = 'content' and @medium = 'image']"))</code>
</pre>
<blockquote>
<p>As an aside, I'm having a bit of trouble getting velocity script
to remove an ampersand. I use this:</p>
</blockquote>
<p>I believe <code>String.replace</code> will only replace the
first occurrence. Instead try something like the following:</p>
<pre>
<code>#set ($thePageTitle = $thePageTitle.replaceAll("&(?!amp;)", '&amp;'))</code>
</pre>
<p>The regex should also ensure you are not double encoding
ampersands.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-11T20:13:54Z2015-05-11T20:13:54ZNot sure how to read part of my XML feed.<div><p>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:</p>
<p>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.</p>
<p>Attached is my transformation. I tried stripping the ampersands
out of every time I read the name, but it's still not working.</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-11T20:52:00Z2015-05-11T20:52:00ZNot sure how to read part of my XML feed.<div><p>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:</p>
<pre>
<code>#set ($images = $_XPathTool.selectNodes($item, "*[local-name() = 'content' and @medium = 'image']"))</code>
</pre>
<p>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:</p>
<pre>
<code>#set ($images = $_XPathTool.selectNodes($item, "/media[local-name() = 'content' and @medium = 'image']"))</code>
</pre>
<p>or</p>
<pre>
<code>#set ($images = $_XPathTool.selectNodes($item, "media[local-name() = 'content' and @medium = 'image']"))</code>
</pre>
<p>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.</p>
<p>Also, how do I read the URL out of the tag? I can't figure out
the code to grab it.</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-12T15:21:20Z2015-05-12T15:21:20ZNot sure how to read part of my XML feed.<div><p>Hi,</p>
<blockquote>
<p>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:</p>
</blockquote>
<p>Curious, but have you tried using the Escape Tool instead to
escape entities? Perhaps try adjusting the end of your
<code>GetPageName</code> macro to the following:</p>
<pre>
<code>#set ($thePageTitle = $_EscapeTool.xml($thePageTitle.value))</code>
</pre>
<p>Note: we're setting the variable to the <code>.value</code> now
instead of the Element itself, so you will want to adjust
references later in your script to no longer use
<code>$thePageTitle.value</code>.</p>
<blockquote>
<p>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:</p>
</blockquote>
<p>The reason your XPath queries won't work is because
<code>media</code> is a namespace, not a node name.</p>
<p>Ideally, you would use <code>media:content</code> 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.</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>Your best bet would be to check the value of the
<code>url</code> attribute as follows:</p>
<pre>
<code>#set ($images = $_XPathTool.selectNodes($contentRoot, "//*[local-name() = 'content' and @medium = 'image']"))
#foreach($image in $images)
#set ($url = $image.getAttribute("url").value)
## ... add logic to check $url here ...
#end</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-12T21:43:07Z2015-05-12T21:43:07ZNot sure how to read part of my XML feed.<div><p>I'm still getting the same problem with the ampersands, but the
URL request worked.</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-13T12:54:56Z2015-05-13T12:54:56ZNot sure how to read part of my XML feed.<div><p>Thank you for following up. I am glad to hear you were able to
access the URL attribute.</p>
<blockquote>
<p>I'm still getting the same problem with the ampersands</p>
</blockquote>
<p>Did you have a chance to try out the Escape Tool? If so, and
that still doesn't work, it sounds like that <code>&amp;</code>
in the URL might be double-encoded. Perhaps try the following to
see if it helps:</p>
<pre>
<code>#set ($thePageTitle = $thePageTitle.replaceAll("&amp;amp;", "&"))</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-13T13:38:06Z2015-05-13T13:38:06ZNot sure how to read part of my XML feed.<div><p>Still the same problem. This is the error I get:</p>
<p>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.</p>
<p>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.</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-13T15:30:43Z2015-05-13T15:30:43ZNot sure how to read part of my XML feed.<div><p>Thank you for testing.</p>
<p>Curious, but I noticed the following line appears to be
incorrect:</p>
<pre>
<code>##set ($pageTitle = $pageTitle.replaceAll("&(?!amp;)", '&amp;'))</code>
</pre>
<p>Perhaps this regex might still work. Let's try correcting this
to see if you still get the error:</p>
<pre>
<code>#macro (GetPageName $page)
## Reset the page title variables
#set ($pageTitle = "")
#set ($pageDisplayName = "")
#set ($thePageTitle = "")
## Grab page "title"
#set ($pageTitle = $page.getChild("title"))
## Grab page "display-name"
#set ($pageDisplayName = $page.getChild("display-name"))
#if ($pageDisplayName && $pageDisplayName.value != "")
#set ($thePageTitle = $pageDisplayName)
#elseif ($pageTitle && $pageTitle.value != "")
#set ($thePageTitle = $pageTitle)
#else
#set ($thePageTitle = $page.getChild("name"))
#end
#set ($thePageTitle = $thePageTitle.replaceAll("&(?!amp;)", '&amp;'))
#end</code>
</pre>
<blockquote>
<p>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.</p>
</blockquote>
<p>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.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-13T16:18:28Z2015-05-13T16:18:28ZNot sure how to read part of my XML feed.<div><p>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?</p>
<p>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?</p></div>webadmintag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-05-13T16:50:13Z2015-05-13T16:50:13ZNot sure how to read part of my XML feed.<div><p>Bummer, thank you for trying anyway.</p>
<blockquote>
<p>I assume that wouldn't affect anything once it's commented,
right?</p>
</blockquote>
<p>Correct, it will not be executed as long as you have the line
commented out.</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>Perhaps try surrounding the entire content with a CDATA tag
(<code><![CDATA[ ... ]]></code>) to see if you can at least
render the invalid XML and see the output.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/368018722015-06-17T13:53:24Z2015-06-17T13:53:24ZNot sure how to read part of my XML feed.<div><p>Hi,</p>
<p>Just wanted to check in to see if you saw <a href="http://help.hannonhill.com/discussions/velocity-formats/11937-not-sure-how-to-read-part-of-my-xml-feed#comment_36826137">
Ryan's last comment</a>. Let us know if you need more help.</p>
<p>Thanks</p></div>Tim