While trying to build an Grape-based API with complex XML body requests in the requests, I came to the point of figuring out how to reach XML attributes in a sample request like this.
<Travelers> <Traveler> <AnonymousTraveler> <PTC Quantity="1">ADT</PTC> </AnonymousTraveler> </Traveler> </Travelers>
XML attributes when using Nokogiri are parsed as normal child elements, and the content (or text) of the element itself is parsed as an String named
So Grape parameters block should look like this in order to parse properly params.
optional :Travelers, type: Array do requires :Traveler, type: Hash do optional :AnonymousTraveler, type: Hash do requires :PTC, type: Hash do requires :Quantity, type: Integer requires :__content__, type: String end end end end
I hope it helps.