# XML file using Nokogiri gem

**URL:** <https://www.ruby-forum.com/t/xml-file-using-nokogiri-gem/177636>\
**Category:** Rails\
**Created:** [October 21, 2009, 12:27pm UTC](https://www.ruby-forum.com/t/xml-file-using-nokogiri-gem/177636 "2009-10-21T12:27:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghanshyam\_6786](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@ghanshyam\_6786](https://www.ruby-forum.com/u/ghanshyam_6786)\
**Post date:** [October 21, 2009, 12:27pm UTC](https://www.ruby-forum.com/t/xml-file-using-nokogiri-gem/177636/1 "2009-10-21T12:27:39Z")

</div>

Hello friends,

Can you guys give me some idea about how to Create XML file using  
Nokogiri gem.

---

<div class="post-metadata">

**Author:** ![ghanshyam\_6786](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@ghanshyam\_6786](https://www.ruby-forum.com/u/ghanshyam_6786)\
**Post date:** [October 21, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/xml-file-using-nokogiri-gem/177636/2 "2009-10-21T23:32:29Z")

</div>

Ghanshyam Rathod wrote:

> Can you guys give me some idea about how to Create XML file using  
> Nokogiri gem.

I could be wrong, but isn’t Nokogiri used for parsing and searching XML?  
I think you should be using Builder for creating XML documents:

[http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=C00000654&name=Builder#](http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=C00000654&name=Builder#)

---

<div class="post-metadata">

**Author:** ![ghanshyam\_6786](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@ghanshyam\_6786](https://www.ruby-forum.com/u/ghanshyam_6786)\
**Post date:** [October 22, 2009, 2:26am UTC](https://www.ruby-forum.com/t/xml-file-using-nokogiri-gem/177636/3 "2009-10-22T02:26:51Z")

</div>

On Thu, Oct 22, 2009 at 10:32 AM, Robert W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ghanshyam Rathod wrote:
> 
> > Can you guys give me some idea about how to Create XML file using  
> > Nokogiri gem.
> 
> I could be wrong, but isn’t Nokogiri used for parsing and searching XML?  
> I think you should be using Builder for creating XML documents:

Nokogiri includes a builder mechanism, too. Here’s some example code  
Ghanshyam:

> <https://github.com/kete/kete/blob/master/lib/workers/excel_based_importer_worker.rb>

# starting at line 56

Cheers,  
Walter  
Kete Project Lead

---

<div class="post-metadata">

**Author:** ![ghanshyam\_6786](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@ghanshyam\_6786](https://www.ruby-forum.com/u/ghanshyam_6786)\
**Post date:** [October 22, 2009, 7:54am UTC](https://www.ruby-forum.com/t/xml-file-using-nokogiri-gem/177636/4 "2009-10-22T07:54:24Z")

</div>

Walter McGinnis wrote:

> On Thu, Oct 22, 2009 at 10:32 AM, Robert W.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Ghanshyam Rathod wrote:
> > 
> > > Can you guys give me some idea about how to Create XML file using  
> > > Nokogiri gem.
> > 
> > I could be wrong, but isn’t Nokogiri used for parsing and searching XML?  
> > I think you should be using Builder for creating XML documents:
> 
> Nokogiri includes a builder mechanism, too. Here’s some example code  
> Ghanshyam:
> 
> [kete/lib/workers/excel\_based\_importer\_worker.rb at master · kete/kete · GitHub](http://github.com/kete/kete/blob/master/lib/workers/excel_based_importer_worker.rb)
> 
> # starting at line 56
> 
> Cheers,  
> Walter  
> Kete Project Lead

Hi cheers,

I m using Builder for Nokogiri (Nokogiri::XML::Builder.new).  
But i m facing problem with displaying XML file in view.

see the code i have used [http://pastie.org/663424](http://pastie.org/663424).  
[http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/Builder.html](http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/Builder.html)

Please give me guide for displaying XML file.

---

<div class="post-metadata">

**Author:** ![ghanshyam\_6786](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@ghanshyam\_6786](https://www.ruby-forum.com/u/ghanshyam_6786)\
**Post date:** [October 22, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/xml-file-using-nokogiri-gem/177636/5 "2009-10-22T15:13:18Z")

</div>

Ghanshyam Rathod wrote:

> I m using Builder for Nokogiri (Nokogiri::XML::Builder.new).  
> But i m facing problem with displaying XML file in view.
> 
> see the code i have used [http://pastie.org/663424](http://pastie.org/663424).

Are you already using Nokogiri in other parts of your application? If  
not then why force the dependency on it just to render that tiny bit of  
XML? The built-in XML Builder would work just fine for that.

> [http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/Builder.html](http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/Builder.html)
> 
> Please give me guide for displaying XML file.

Can you clarify? Do you mean that you’re having trouble rendering the  
XML response? Displaying XML doesn’t make a lot of sense. Browsers  
render HTML/XHTML not XML (well okay some browsers do as a convenience  
for development, but that’s not intended for “normal” web use).
