Вопрос

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
Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top