-2

我需要使用builder创建以下xml,我该怎么做?

<rss xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.2/">
  <channel>
    <title>Your Site Title</title>
    <link>http://example.com</link>
    <pubDate>Tue, 02 Oct 2012 13:52:46 +0000</pubDate>
    <description />
    <language>en-US</language>
    <wp:wxr_version>1.2</wp:wxr_version>
    <wp:author>
      <wp:author_id>608422065</wp:author_id>
      <wp:author_login>xxx@hotmail.com</wp:author_login>
      <wp:author_email>xxx@hotmail.com</wp:author_email>
      <wp:author_display_name><![CDATA[abc123]]></wp:author_display_name>
      <wp:author_first_name><![CDATA[abc123]]></wp:author_first_name>
      <wp:author_last_name><![CDATA[abc123]]></wp:author_last_name>
    </wp:author>
    <wp:category>
      <wp:cat_name><![CDATA[null - null]]></wp:cat_name>
      <wp:category_nicename>null-null</wp:category_nicename>
      <wp:category_parent />
    </wp:category>
</channel>
</rss>
4

1 回答 1

2

这应该让你开始:

xml = Builder::XmlMarkup.new
xml.rss "xmlns:excerpt" => "http://...", "xmlns:content" => "http://..." do
  xml.channel do
    xml.title "Your Site Title"
    xml.description
    xml.wp :wxr_version, "1.2"
    xml.wp :author do
      xml.wp :author_id, "608422065"
    end
  end
end

会产生

<rss xmlns:excerpt="http://..." xmlns:content="http://...">
  <channel>
    <title>Your Site Title</title>
    <description />
    <wp:wxr_version>1.2</wp:wxr_version>
    <wp:author>
      <wp:author_id>608422065</wp:author_id>
    </wp:author>
  </channel>
</rss>
于 2012-10-04T23:11:25.577 回答