# Help required in generating xml + sinatra

**URL:** <https://www.ruby-forum.com/t/help-required-in-generating-xml-sinatra/175194>\
**Category:** Ruby\
**Created:** [September 9, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/help-required-in-generating-xml-sinatra/175194 "2009-09-09T14:10:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e8c25b/32.png) [@kingston](https://www.ruby-forum.com/u/kingston)\
**Post date:** [September 9, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/help-required-in-generating-xml-sinatra/175194/1 "2009-09-09T14:10:10Z")

</div>

hello,  
this is my sintra code can any one tell why xml isn’t been generated on  
browser

####### this is my sinatra code############

get ‘/multiquery.xml’ do  
content\_type(‘text/xml’)  
array\_of\_names = params[:name]  
‘#{construct\_xml(array\_of\_names)}’  
end

the method construct\_xml look like this

def construct\_xml(names)  
xml = Builder::XmlMarkup.new(:indent =\>1)  
xml.instruct!  
names.each do |name|  
xml.queryresponse {  
xml.name “#{name}”  
xml.credential “Engineer”  
}  
end  
return xml  
end

Now the point is that the method “construct\_xml” construct the  
appropriate xml  
but the the xml doesn’t appear in browser  
and the line of code ‘#{construct\_xml(array\_of\_name)}’ run into “XML  
Parsing Error: not well-formed”

iam sure that xml is formed properly.i mean to say the i have set the  
:target =\> $stdout

like this  
Builder::XmlMarkup.new(:target =\>$stdout ,:indent =\>1)  
and the xml is constructed properly in console  
ent .Is there any thing that I am missing.

please reply

thanks anyway

---

<div class="post-metadata">

**Author:** ![kingston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e8c25b/32.png) [@kingston](https://www.ruby-forum.com/u/kingston)\
**Post date:** [September 9, 2009, 4:45pm UTC](https://www.ruby-forum.com/t/help-required-in-generating-xml-sinatra/175194/2 "2009-09-09T16:45:44Z")

</div>

You use single quotes. Those are not interpolated.

If you do “#{construct\_xml(array\_of\_names)}”, everything should work.

Regards,  
Skade

On Sep 9, 2009, at 9:40 AM, Ken G. wrote:

> ‘#{construct\_xml(array\_of\_names)}’  
> xml.credential “Engineer”
> 
> ## thanks anyway
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Florian G.

smtp: removed\_email\_address@domain.invalid  
jabber: removed\_email\_address@domain.invalid  
gpg: 533148E2

---

<div class="post-metadata">

**Author:** ![kingston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e8c25b/32.png) [@kingston](https://www.ruby-forum.com/u/kingston)\
**Post date:** [September 9, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/help-required-in-generating-xml-sinatra/175194/3 "2009-09-09T18:21:46Z")

</div>

On Sep 9, 2009, at 07:44 , Florian G. wrote:

> You use single quotes. Those are not interpolated.
> 
> If you do “#{construct\_xml(array\_of\_names)}”, everything should work.

Better, don’t use quotes for no reason:

construct\_xml(names)

> On Sep 9, 2009, at 9:40 AM, Ken G. wrote:
> 
> > get ‘/multiquery.xml’ do  
> > content\_type(‘text/xml’)  
> > array\_of\_names = params[:name]  
> > ‘#{construct\_xml(array\_of\_names)}’  
> > end

“array\_of\_” is equally useless. plural implies a collection.

> > …

> > iam sure that xml is formed properly.i mean to say the i have set  
> > the  
> > :target =\> $stdout
> > 
> > like this  
> > Builder::XmlMarkup.new(:target =\>$stdout ,:indent =\>1)  
> > and the xml is constructed properly in console  
> > ent .Is there any thing that I am missing.

Yes, there is something REALLY OBVIOUS that you’re missing. A test.

The SIMPLEST of tests would have made this entire question obvious.
