What is the right syntax to use to grab a node with a colon in it?

Eric's Avatar

Eric

26 Aug, 2014 03:16 PM

I have this node called <content:encoded> and I'm trying to grab it with xpath and velocity. Is there anything special that I need to do to escape that colon?

#set ($jobs = $_XPathTool.selectNodes($contentRoot, "//item"))
#set ($count = 1)
<h3 class="career_banner">Featured Jobs</h3>

<div id="jobs-box">
    <ul>
    #foreach($job in $jobs)
        #if($count <= 4)
               #set( $content = $job.getChild('content:encoded'))
                    <li>$_SerializerTool.serialize(${content}, true)</li>
                #set ($count = $count + 1)   
        #end
    #end
    </ul>
</div>

I seem to be running into trouble with #set( $content = $job.getChild('content:encoded')), so I'm wondering if the colon has anything to do with it?

  1. 1 Posted by Ryan Griffith on 26 Aug, 2014 03:32 PM

    Ryan Griffith's Avatar

    Hi Eric,

    Accessing items that contain a namespace can be a little tricky, because the underlying library does not handle them properly. When you have a moment, try the workaround that is mentioned on this issue and let me know how it works out.

    To summarize, you have to obtain and loop over all of the children of a given Element and check the value returned by getName().

    Please let me know if you have any questions.

    Thanks!

  2. Ryan Griffith closed this discussion on 03 Sep, 2014 08:00 PM.

Comments are currently closed for this discussion. You can start a new one.

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