Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Nokogiri to search through XML file based on user input in Rails app
    primarykey
    data
    text
    <p>So I've got an XML file (<a href="http://www.treasury.gov/ofac/downloads/sdn.xml" rel="nofollow">XML file</a>) with a schema (<a href="http://www.treasury.gov/resource-center/sanctions/SDN-List/Documents/sdn.xsd" rel="nofollow">XML schema</a>).</p> <p>I'm trying to create a quick Rails app to allow users to search through the XML file based on the 'lastName" element that are children of an sdnEntry element.</p> <p>I don't have any problems setting up the rails app, or the search-form. I was also able to get the XML file loaded using Nokogiri and can run simple commands like...</p> <pre><code>xmldoc.css("lastName") </code></pre> <p>...to return a NodeSet with all the 'lastName' elements in them. Unfortunately, that's not good enough, since that lists not just the 'lastName' elements directly underneath an 'sdnEntry' element. Plus that doesn't even get me started to insert the user's input from the form. I was thinking something like this would work...</p> <pre><code>xmldoc.xpath("/xmlns:sdnList/sdnEntry/lastName[text()='#{param[:name]}']") </code></pre> <p>...but that didn't work. Oddly, I couldn't even get...</p> <pre><code>xmldoc.xpath("/xmlns:sdnList/sdnEntry/lastName") </code></pre> <p>...to work. I just don't know enough about Nokogiri or XPath or CSS queries for XML documents to figure out how to pass the param from user-input form to create the appropriate query that will return the right info for me.</p> <p>I tried looking through the <a href="http://nokogiri.org/tutorials/searching_a_xml_html_document.html" rel="nofollow">Nokogiri Documentation</a> and the <a href="http://www.w3schools.com/xpath/" rel="nofollow">W3Schools XPath Tutorial</a>. No joy.</p> <p>I would really appreciate any pointers, code snippets or suggestions. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload