Ruby on Rails
Thursday, October 25, 2012
my code looks like this:
xml.instruct!
xml.county(name: @jurisdiction.name, id: @jurisdiction.jurisdictionID) do
xml.officials do
@officials.each do |official|
xml.official do
xml.firstname official.firstname
xml.lastname official.lastname
xml.eotypeID eotypeID: official.eotypeID
xml.eotype EoType.find(official.eotypeID).name
xml.sourceID sourceID: official.sourceID
xml.source SourceType.find(official.sourceID).name
end
end
end
end
which produces this:
<county name="Some Town" id="9999999999">
<officials>
<official>
<firstname>Hector</firstname>
<lastname>Someone</lastname>
<eotypeID eotypeID="1"/>
<eotype>Primary</eotype>
<sourceID sourceID="1"/>
<source>State Web Site</source>
</official>
<official>
<firstname>Lucy</firstname>
<lastname>Someone-Else</lastname>
<eotypeID eotypeID="3"/>
<eotype>Registration</eotype>
<sourceID sourceID="6"/>
<source>History</source>
</official>
</officials>
</county>
I would like to change it to produce this:
<county name="Some Town" id="9999999999">
<officials>
<official>
<firstname>Hector</firstname>
<lastname>Someone</lastname>
<eotypeID eotypeID="1"/>
<eotype>Primary</eotype>
<sourceID sourceID="1"/>
<source>Web Site</source>
</official>
<official>
<firstname>Lucy</firstname>
<lastname>Someone-Else</lastname>
<eotype eotypeID="3">Registration</eotype>
<source sourceID="6">History</source>
</official>
</officials>
</county>
I cannot find any documentation or examples on the point. Can someone offer a helpful hint or point to some useful documentation that covers the subject, where the primary point is this: Using XML Builder, or some other facility, how does one emit an element instance that has both attributes and non-empty content? There are losts of ways to do it with brute force; just trying to find an "elegant" solution.
Thanks for any suggestions
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/nV3s1ulAMxUJ.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment