Frage

Is there a more elegant way to get the contents of text nodes with Nokogiri? Right now I'm using something like this:

<?xml version="1.0" encoding="UTF-8"?>
  <TestCase>
    <ID>53</ID>
    <Code>WKDO-188465</Code>
  </TestCase>


xml   = Nokogiri::XML(File.open('test.xml'))
id    = xml.at_css('TestCase ID').children.first.text
code  = xml.at_css('TestCase Code').children.first.text
War es hilfreich?

Lösung

In this case you use the text-method on the elements directly.

xml   = Nokogiri::XML(File.open('test.xml'))
id    = xml.at_css('TestCase ID').text
code  = xml.at_css('TestCase Code').text
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top