Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:36:56+00:00 2026-05-27T18:36:56+00:00

Following is the method used to write an entry to xml file def write_entry(entry)

  • 0

Following is the method used to write an entry to xml file

def write_entry(entry)
  node = Nokogiri::XML::Node.new("url", @xml_document)
  node["loc"]= entry[:url]
  node["lastmod"]= entry[:lastmod].to_s
  node["changefreq"] =  entry[:frequency].to_s
  node["priority"] = entry[:priority].to_s
  node.to_xml
end

The entry looks like this:

<urlset>
  <url loc="http:`enter code here`//www.experteer.co.uk/vacaturebank/banen/vacatures/xing-ag" lastmod="2011-11-23 16:58:27 UTC" changefreq="0.8" priority="monthly"/>
</urlset>

I want the entry of xml to be like this

<urlset>
  <url>
    <loc> http://www.experteer.co.uk/vacaturebank/banen/vacatures/xing-ag </loc>
    <lastmod> 2011-11-23 16:58:27 UTC </lastmod>
    <changefreq> 0.8 </changefreq>
    <priority> monthly </priority>
  </url>
 </urlset>

Is it possible with using Node or I have to use Builder?
If possible with Node Then how?
and If I have to use Builder it writes header for each entry how can I handle that it dont write header for each entry.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:36:56+00:00Added an answer on May 27, 2026 at 6:36 pm

    you can use << or add_child to append children nodes to a node.

    def write_entry(entry)
      url = Nokogiri::XML::Node.new( "url" , @xml_document )
      %w{loc lastmod changefreq priority}.each do |node|
        url <<  Nokogiri::XML::Node.new( node, @xml_document ).tap do |n| 
                  n.content = entry[ node.to_sym ] 
                end  
      end
      url.to_xml
    end
    

    For this to work correctly, you have to change entry[:url] to entry[:loc]. and entry[:frequency] to entry[:changefreq], which shouldn’t be a bad thing (it’s best to have the same name for the same thing everywhere, isn’t it ?).

    Alternatively, if your entry hash only contains what you need to convert to xml, use entry.each do |key,value| instead of the array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write string to an xml file in Silverlight. When I used
I used following documentation to write a method in Vala to send key press
I have the following method (used to generate friendly error messages in unit tests):
I'm used to doing basic password protection for Apache w/ the following method in
How come when I use the following method, to be used to convert all
Say we have the following method: private MyObject foo = new MyObject(); // and
I have created a method in my java assignment to write into a file
With the following file as input of xsltprocessor : mylibrary.xml : <library> <book isbn=1/>
I was using the following to write to a file: using(Stream FileStream = File.OpenWrite(FileName))
The following method does not work because the inner block declares a variable of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.