Can't manage to parse XML collection properly
This is probably an issue on my end that I'm doing something wrong, but I can't seem to parse this XML collection properly. The XML looks like:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.SupermarketAPI.com">
<string>Apples</string>
<string>Gerber 100% Apple Juice - 32 Fl. Oz.</string>
<string>Gerber Apple Juice - 4-4 Fl. Oz.</string>
<string>Gerber Organic Apple Juice - 4-4 Fl. Oz.</string>
<string>Pedialyte Tetra/Brick Pk Apple Flavor - 4-6.8 Fl. Oz.</string>
</ArrayOfString>
My representer looks like:
require 'representable/decorator'
require 'representable/xml'
require 'representable/xml/collection'
class StringsSerializer < Representable::Decorator
include Representable::XML::Collection
self.representation_wrap = :ArrayOfString
# TODO: this belongs in `Representable::XML::Collection`
# REF: https://github.com/apotonick/representable/issues/119
def self.remove_namespaces!
representable_attrs.options[:remove_namespaces] = true
end
remove_namespaces!
items wrap: :string
end
And I'm parsing via:
StringsSerializer.new([]).from_xml(raw_xml)
The result is a collection where each entry is the Nokogiri::XML::Element rather than the String representing the text child of each element. For example, my tests are failing with messages like:
object at index 0 failed to match:
expected #<Nokogiri::XML::Element:0x3fe7b9f4a3b8 name="string" children=[#<Nokogiri::XML::Text:0x3fe7b9f46b00 "Apples">]> to be a kind of String
Any idea where I'm going wrong here? I imagine it's probably just a problem on my side.
Weird, can you find a test case in Representable that proofs this actually does work?
Sorry, I missed your response from before! I'll take a look and follow up.