-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't have an array with plural names ? #17
Comments
I don't believe I've tested this case. If you'd write a failing test case and push it out, I'd find it very helfull, but in the mean time, have you taken a look at the :from option? When you explicitly specify what node you'd like to query from, roxml should always honor that. In short: xml_reader :books, :as => SomeIdAndNameObject, :from => 'books', :in => 'some_node' I can't give any guarantees, but that's a likely fix. |
Hi, thanks for your answer. I've tried what you suggest and it doesn't work. Here is the exact code I ran : require 'rubygems'
require 'roxml'
require 'pp'
xml = %(
<myxml>
<store>
<books><id>1</id><title>first book</title></books>
<books><id>2</id><title>second book</title></books>
<books><id>3</id><title>third book</title></books>
</store>
</myxml>
)
class Book
include ROXML
xml_reader :id, :as => Integer
xml_reader :title
end
class Store
include ROXML
xml_reader :books, :from => 'books', :in => 'store', :as => [Book]
end
class MyXml
include ROXML
xml_reader :store, :as => Store
end
pp MyXml.from_xml(xml).store.books About the failing test, I'm still in the learning process of writing tests and I'm not familiar with the way you organized your specs. I you tell me which spec file I should write my test in, I'd try to make one and send you a pull request. Cheers |
+1 I can't get ROXML to parse this:
My Activity class (using the dasherize xml_convention) defines this:
I believe it is looking for _datum instead of _datas (the ROXML::Definition @name is 'comment-engagement-datum'): Can I override this somehow? Thanks. |
I verified my suspicion by making the field required and getting this: Hope that helps. |
Hi findchris, this has to do with ActiveSupport's pluralization, which you can override in the same way you would in rails, by establishing inflection rules: http://as.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html Normally this would happen in a rails initializer, but you should be able to do it in a lib after you require roxml just as well. |
@Empact I added a rule like:
I don't think that worked. However, using this line seemed to do the trick:
I guess I didn't need the ':from' option. Thanks for your reply and for ROXML :-) -Chris |
Thank you Chris . I had exactly the same problem with taxes and Tax..... |
The problem is that the singularization is made after the assignment from :from
Maybe the proper fix would be to apply "signularize" only to @attr_name |
@vihai Good find. Fork and pull request? |
I have forked and committed a patch but I'm not yet sure how this whole git-stuff works... Let me try to send a pull request but I cannot guarantee the results :) |
I applied it to my branch. Maybe @Empact will do the same. |
Alright, I applied the fix and speced it using jlecour's example in spec/xml/array_spec.rb Note there was a problem in the original fix that it wouldn't stringify symbolic :from, which is fixed in my master. So, this should be fixed. Thanks guys! |
Thanks guys for this fix. I can't confirm yet that it's OK for my original situation, but I'll do it as soon as I can. |
Hi, I'm consuming a WebService that gives me some weird XML.
I have something like
I'd like to have an array of "books", but it seems impossible (as far as I can tell) because the "books" node name is already a plural.
I know, I should be singular in the first place, but I don't control this, it comes from a major player in the tourism industry.
I've tried many things, including specifying an explicit :from, … but it doesn't work.
If I create a copy of the XML and change "books" into a singular node, it's working great.
Any idea on how I can do this ?
The text was updated successfully, but these errors were encountered: