Ruby on Rails Xml Builder


calling xml partail to get string :

@abc = render_to_string(partial: “/assignments/test_data”, :formats => [:xml], :locals=> {:account=> @account})

 

Make a patiral with like “/assignments/_test_data.xml.builder’

and following content is to build an xml file with tree structure and inserting attributes in nodes is also provided

 

xml.instruct!

xml.Umschlag :version=> “1.0” do
xml.Anfrage :version=> “1.0” do
xml.Header do
xml.SammelKennziffer(12345)
xml.SammelPasswort(12345678)
end #header tag end
xml.Person  :version=> “1.0” do
xml.Personendaten do
xml.Nachname(@person_info.last_name) #lastname
xml.Vorname(@person_info.first_name)
xml.Geschlecht do
xml.MAENNLICH
end
xml.Geburtsdatum(‘24.12.1919’)
xml.Adresse do
xml.Strasse(‘St#1 H#390’)
xml.PLZ(‘798247’)
xml.Ort(‘Baden-Baden’)
end
end #persondaten tag end

xml.MerkmalListe do
xml.Merkmal do
xml.MerkmalCode(‘ST’)
xml.Kontonummer(‘54321’)
end#Merkmal tag end

end# MerkmalListe tag ends
end#person tag end
xml.assignment do

xml.nombre(@assignment.id)
xml.account_id(account.id)
xml.expired_at(@assignment.expired_at)
xml.decline_reason(@assignment.decline_reason)
xml.promotion(@assignment.promotion)

end # assignment tag end

end #Anfrage tag end
end# Umschlag tag end

Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Posted in Ruby Little Codes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: