I'm having problems accessing a raw XML object from a Builder :: XmlMarkup object.
irb> xml = Builder::XmlMarkup.new(:target => '') => <pretty_inspect/> irb> xml.foo("bar") => "<pretty_inspect/><foo>bar</foo>" irb> puts xml TypeError: can't convert Builder::XmlMarkup to Array (Builder::XmlMarkup#to_ary gives String) from (pry):122:in `puts'
In the script where I use Builder to create XML, I pass @xml POST:
response = HTTParty.post(API_ENDPOINT, :body => @xml)
This gives the same error:
TypeError (can't convert Builder::XmlMarkup to Array (Builder::XmlMarkup#to_ary gives String)):
Of course, if I do @ xml.to_xml, it does not return an error, but adds </to_xml> to xml, that is, it does not actually convert the XML object to xml. This is not what I want.
So, how can I access xml to pass it to my post without adding additional nodes to my XML?
Edit: Possible Solution
Doing @xml.target! seems like a solution to the problem, but I'm not sure I understand why.
response = HTTParty.post(API_ENDPOINT, :body => @xml.target!)
Perhaps someone can help me understand what is happening here.
source share