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.
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
sdnEntryand performs a completely naive huge dump of all the XML. If you want specific nodes, then you should have said so.And here’s the output that particular template would create: