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

  • SEARCH
  • Home
  • 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 8565387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:24:56+00:00 2026-06-11T17:24:56+00:00

I need to generate an xml for a feed which looks roughly like this

  • 0

I need to generate an xml for a feed which looks roughly like this :-

    <?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
    <item>
        <g:id><![CDATA[id]]></g:id>
        <title><![CDATA[Product Name]]></title>
        <description><![CDATA[This should be a relatively detailed description with as little formatting as possible.]]></description>
        <g:brand>Brand X</g:brand>
        <g:sale_id>new</g:sale_id>
    </item>
    <item>
        Next product...
    </item>
</channel>
</rss>

My code currently looks something like this :-

xml=Builder::XmlMarkup.new(:indent => 3)
xml.instruct!
xml.rss("version" => "2.0" ,  "xmlns:g" => "http://base.google.com/ns/1.0" , "xmlns:atom" => "http://www.w3.org/2005/Atom"){
xml.channel{
# remove xml.namespace = xml.namespace_definitions.find{|ns|ns.prefix=="atom"}
sale_products.each do |sp|
  sid = (products_info[sp.product_id]["sale_id"]).to_s()
  xml.item {
    #xml.id{ |xml| xml.cdata!(products_info[sp.product_id].own_id) }
    #xml.g :id,{ xml.cdata!("sdaf") }
    xml.product_title{ |xml| xml.cdata!(products_info[sp.product_id].name) }
    xml.description{ |xml| xml.cdata!(ActionController::Base.helpers.strip_tags(products_info[sp.product_id].description)) }
    xml.item {
      xml.brand { |xml| xml.cdata!(products_info[sp.product_id].designer_1) }
      xml.sale_id{ |xml| xml.cdata!(sid) }
    }
  }

end
}
}

My problem is around getting both namespace prefixes and cdata tags working at the same time.

xml.g :id, "fdsafsad"

This gets the namesapce prefix.

xml.product_title{ |xml| xml.cdata!(products_info[sp.product_id].name) }

This gets cdata tags around the values.

xml.g :id,{ xml.cdata!("sdaf") }

This fails to do the trick.

How do i get both the namespace prefix as well as the cdata tags working at the same time for the same tag. What am I doing wrong?

Edit:- The output that I am currently getting is like:-

<g:id>
   <![CDATA[10005-0003]]>
</g:id>

The output that I want should just have the value inside cdata tags (no newline etc) :-

<g:id><![CDATA[10005-0003]]></g:id>

Note that I do not want to remove the :indent => 3 while creating the markup, so that other tags are formatted as required.

  • 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-06-11T17:24:57+00:00Added an answer on June 11, 2026 at 5:24 pm
    xml.tag!("g:id") { xml.cdata!("sdaf") }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need so generate XML like the following: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <urlset xmlns=http://www.sitemaps.org/schemas/sitemap/0.9
I need to generate XML in the following form: <ns1:root xmlns:ns1=http://example.com/xmlns1 xmlns:ns2=http://example.com/xmlns2> <ns2:item ns2:param=value
I need a Class which has an semi-automatic 'to_s' method (to generate XML in
I need to generate this simple looking XML, looking for a clean way to
I need to generate a PDF version of the docbook.xml documentation (5.0) when building
I need to generate the following XML: <Learner xmlns=some.domain.api> <ActivationDate>1999-05-31T11:20:00</ActivationDate> <EmailAddress>String content</EmailAddress> <ExpirationDate>1999-05-31T11:20:00</ExpirationDate> <FederalId>String
I need to generate module.xml file for JBoss7 for a maven project which has
I need to generate XML on MonoTouch application ? How i can create like
What tool do I need to generate XML intellisense help file as shown below?
Flex has an issue with hyphens in xml. I need to generate an xml

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.