| Class | LibXML::XML::Parser |
| In: |
lib/parser.rb
|
| Parent: | Object |
Array of elements from XML parseed by retrieving each elements content.
| string: | the XML to parse. |
| path: | the path to find in the XML. |
# File lib/parser.rb, line 38
38: def content(string, path)
39: string(string).parse.find(path).inject([]) do |arr, el|
40: arr << el.content.strip
41: end
42: end
Array of elements from XML parsed by retrieving attribute value for each element in path of XML.
| string: | the XML to parse. |
| path: | the path to find in the XML. |
| attribute: | the attribute to request per element of the XML. |
# File lib/parser.rb, line 10
10: def parse(string, path, attribute)
11: string(string).parse.find(path).inject([]) do |arr, el|
12: arr << el.attributes[attribute]
13: end
14: end
Array of elements from XML parsed by retrieving attribute value for each element in path of XML taking care to return nils for values that don‘t have the inner path but do have the outer path. Default case this would be ignore resulting in a shorter array.
| string: | the XML to parse. |
| path: | the path to find in the XML. |
| inner_path: | the inner path to find in the XML. |
| attribute: | the attribute to request per element of the XML. |
# File lib/parser.rb, line 26
26: def parse_with_nils(string, path, inner_path, attribute = 'id')
27: string(string).parse.find(path).inject([]) do |arr, el|
28: inner = el.find(inner_path).first
29: arr << (inner ? inner.attributes[attribute] : nil)
30: end
31: end