Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Xml read/write with a nice ruby api

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 benchmark
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
README
XML Node
==========


Example for generating xml:
  
  # Create an atom like document
  
  root = XmlNode.new 'feed' do |feed|
    
    feed << XmlNode.new('id', 'tag:atom.com,2007:1')
    feed << XmlNode.new('title', 'Atom test feed')
    feed << XmlNode.new('author') do |author|
      author << XmlNode.new("name", "tobi")
      author << XmlNode.new("email", "tobi@gmail.com")
    end
    
    feed << XmlNode.new('entry') do |entry|
      entry << XmlNode.new('title', 'First post')
      entry << XmlNode.new('summary', 'Lorem ipsum', :type => 'xhtml')
      entry << XmlNode.new('created_at', Time.now)
    end
    
    feed << XmlNode.new('dc:published', Time.now)
  end
  
  root.to_xml #=> Well formatted xml
  
  
Example for parsing xml:


  xml = XmlNode.parse('<feed attr="1"><element>text</element><element>text</element></feed>')
  xml['attr'] #=> '1'  
  xml.find(:first, 'element')
  xml.find(:all, 'element')
  
  xml.children['element'].text #=> 'text'
  xml.children.each { |e| e... }             
  
Something went wrong with that request. Please try again.