I need to create xml for a feed that looks something 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>
Currently my code 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{
My problem is to use both namespace prefixes and cdata tags 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 will not help.
How to get both a namespace prefix and cdata tags that work simultaneously for the same tag. What am I doing wrong?
Edit : - The result that I am getting now is similar: -
<g:id> <![CDATA[10005-0003]]> </g:id>
The result I want should have a value inside the cdata tags (no newline, etc.): -
<g:id><![CDATA[10005-0003]]></g:id>
Note that I do not want to remove: indent => 3 when creating markup, so that other tags are formatted as needed.