Hi, i need to render a complex xml, that may looks like this:
<container attr1="" attr2="">
<user login="" />
<product name="" version="" />
<anotherTag />
</container>
user and product are the model-objects. container's attributes has values, not related to models, anotherTag has some another information, also not related to models
I need to build several kinds of such xmls and each kind will include his set of model-object, represented in xml format
Currently, i use LibXML to construct all kinds of xml's 'by hands' But, the code going to be heavy...
I know, that model has a nice to_xml method, that can handle associations of multiple levels. This is very useful ... but
It will be great, when i will be able to use to_xml methods to construct xml fragment by fragment, like so:
xml = LibXML::XML::Document.new
xml.root = LibXML::XML::Node.new( 'container' )
xml.root['attr1'] = 'value'
xml.root['attr2'] = 'value'
xml.root << user.to_xml
xml.root << product.to_xml :only => [:login, :name]
# some another custom tags
# ...
I have used happyMapper library, but, as far, as i know, it can only convert from xml, but not to xml.
Is there any way, to construct complex xml's from models and custom data, using declarative approach ?