Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:09:33+00:00 2026-05-26T22:09:33+00:00

So using the advice found in my previous ‘ question ‘, I have been

  • 0

So using the advice found in my previous ‘question‘, I have been able to get the results I want.

I was wondering if anyone had an easy way to display these results in a Rails view that also has non XML content.

I’ve looked into XSLT but don’t know enough about it, especially not in relation to Rails, to know whether that is where I should spend my time. If so, I’d love some pointers on how I can use XSLT in Rails views.

What I am looking for is to display a list of ‘sdnEntry’ results (see ‘XML Schema‘ for details.)

As you will see from the ‘XML Schema‘, not all of the ‘sdnEntry’ items have the same elements. Therefore, I’d like to display the following information about each ‘sdnEntry’, omitting any empty elements where applicable.

Please feel free to ask questions in comments. I really appreciate the help.

EDIT #1: The XML file can be found here. (6MB)

EDIT #2: I’d prefer something like a <dl>/<dt><dd> list. Heck, I’d even settle for a plain old table. As for empty elements, you will see from the schema, that some child elements (like ‘firstName’ or ‘address3’, etc.) have 0 minimum occurrences, and are therefore not found for every ‘sdnEntry’. If possible, I’d rather not show blank child elements. If that’s a problem, I’d be fine with blanks in the end, if needed.

EDIT #3: The results will always be a Nokogiri NodeSet of one or more ‘sdnEntry’ items. That’s all I would need to display. I am confident that with enough guidance or example code, I could apply any provided solution to other needs down the line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:09:33+00:00Added an answer on May 26, 2026 at 10:09 pm

    You still haven’t given enough details about what you actually want for me to give you a good answer, but you’ve given just enough to get an answer. :p

    The following shows how to load your XML file into a Nokogiri document, create a Haml template (which would be part of your Rails view; if you’re using Erb or some other template system, say so) that runs through a list of sdnEntry and performs a completely naive huge dump of all the XML. If you want specific nodes, then you should have said so.

    require 'nokogiri'
    require 'haml'
    
    # Haml helper to create a naive hierarchy of dl/dt/dd for any xml node
    def xml_to_dl(node)
      haml_tag('dl') do
        node.elements.each do |n|
          haml_tag('dt',n.name)
          if n.elements.empty?
            haml_tag('dd',n.text)
          else
            haml_tag('dd'){ xml_to_dl(n) }
          end
        end
      end
    end
    
    # This would be your page.haml view
    template = Haml::Engine.new <<'ENDHAML'
    %section#sdnList
      %h1#sdnList SDN List Awesomeness
      - if @sdns.empty?
        %p.error No entries found. :(
      - else
        %p Here are some exciting sdnEntries. Check em out!
        - @sdns.each do |sdn|
          %h2.name #{sdn.at('lastName').text}, #{sdn.at('firstName').text}
          - xml_to_dl(sdn)
    ENDHAML
    
    # This would be in your controller
    doc  = Nokogiri.XML(IO.read('sdn.xml'))
    doc.remove_namespaces! # Make life easier
    @sdns = doc.xpath('/sdnList/sdnEntry[firstName][position() < 2]')
    
    # This is taken care of by rails
    puts template.render(self)
    

    And here’s the output that particular template would create:

    <section id='sdnList'>
      <h1 id='sdnList'>SDN List Awesomeness</h1>
      <p>Here are some exciting sdnEntries. Check em out!</p>
      <h2 class='name'>GONZALEZ BOHORQUEZ, Guillermo</h2>
      <dl>
        <dt>uid</dt>
        <dd>11764</dd>
        <dt>firstName</dt>
        <dd>Guillermo</dd>
        <dt>lastName</dt>
        <dd>GONZALEZ BOHORQUEZ</dd>
        <dt>sdnType</dt>
        <dd>Individual</dd>
        <dt>programList</dt>
        <dd>
          <dl>
            <dt>program</dt>
            <dd>SDNT</dd>
          </dl>
        </dd>
        <dt>idList</dt>
        <dd>
          <dl>
            <dt>id</dt>
            <dd>
              <dl>
                <dt>uid</dt>
                <dd>6139</dd>
                <dt>idType</dt>
                <dd>Cedula No.</dd>
                <dt>idNumber</dt>
                <dd>6185654</dd>
                <dt>idCountry</dt>
                <dd>Colombia</dd>
              </dl>
            </dd>
            <dt>id</dt>
            <dd>
              <dl>
                <dt>uid</dt>
                <dd>6140</dd>
                <dt>idType</dt>
                <dd>Passport</dd>
                <dt>idNumber</dt>
                <dd>AJ772175</dd>
                <dt>idCountry</dt>
                <dd>Colombia</dd>
              </dl>
            </dd>
          </dl>
        </dd>
        <dt>addressList</dt>
        <dd>
          <dl>
            <dt>address</dt>
            <dd>
              <dl>
                <dt>uid</dt>
                <dd>17790</dd>
                <dt>address1</dt>
                <dd>c/o UNIVISA S.A.</dd>
                <dt>city</dt>
                <dd>Cali</dd>
                <dt>country</dt>
                <dd>Colombia</dd>
              </dl>
            </dd>
          </dl>
        </dd>
        <dt>dateOfBirthList</dt>
        <dd>
          <dl>
            <dt>dateOfBirthItem</dt>
            <dd>
              <dl>
                <dt>uid</dt>
                <dd>7272</dd>
                <dt>dateOfBirth</dt>
                <dd>20 Dec 1944</dd>
                <dt>mainEntry</dt>
                <dd>true</dd>
              </dl>
            </dd>
          </dl>
        </dd>
        <dt>placeOfBirthList</dt>
        <dd>
          <dl>
            <dt>placeOfBirthItem</dt>
            <dd>
              <dl>
                <dt>uid</dt>
                <dd>7273</dd>
                <dt>placeOfBirth</dt>
                <dd>Buga, Valle, Colombia</dd>
                <dt>mainEntry</dt>
                <dd>true</dd>
              </dl>
            </dd>
          </dl>
        </dd>
      </dl>
    </section>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing some testing whilst using Jquery UI datepicker and have found
Many thanks for the advice you have given me thus far. Using testbenches is
I would appreciate any advice here. Based on what I have found on the
I've been using MSTest so far for my unit-tests, and found that it would
After googling a bit I have found some tips about how to get online
I have searched on this and found something about using remotely hosted JSPs but
I want to be able to test if theForm is defined, meaning it found
Does anybody have any advice about using Mercurial as a front end for Perforce?
after some advice regarding a problem i am getting using a linux based piece
I need some advice from experts :) I will develop a website using PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.