[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

XML - converting from one feed to another (beginner

rb

12/29/2006 8:33:00 PM

I'm trying to read an XML feed of products and convert them to a
different XML feed to upload to Froogle (Google Base).

How do I read the lines of XML and then rewrite them in the new XML?
I've started with rexml, but I'm not sure if I'm on the right track.


def convert_to_base_xml(xml)
# Takes a product XML feed and converts it into one that
# is formatted for uploading to Google Base

# doc = REXML::Document.new
feed = REXML::Document.new(xml)

# Create the export XML document
doc = REXML:Document.new
rss = doc.add_element 'rss'

channel = doc.add_element 'channel'

# Loop through old feed and create new feed based
# on that data
feed.each_child do |child|
#add items to new rss feed, see below

# I'm not sure what I should do here

end

# Save rss feed to a file

end

# original feed XML
# <item>
# <viewName></viewName>
# <artist></artist>
# <artist_url></artist_url>
# <title></title>
# <title_url></title_url>
# <catName></catName>
# <cat_url></cat_url>
# <cat></cat>
# <codeName></codeName>
# <id></id>
# <previewPath><previewPath>
# <imagePath></imagePath>
# </item>
#
# Convert to an RSS 2.0 feed in this format:
#
# <item>
# <title></title>
# <link></link>
# <g:artist></g:artist>
# <description></description>
# <g:brand></g:brand>
# <g:label></g:label>
# <g:image_link></g:image_link>
# <g:product_type><g:product_type>
# <g:price></g:price>
# </item>