Skip to content
Xml read/write with a nice ruby api
Find file
Latest commit b60fe29 @Soleone Soleone committed with Added to_xml_value support for Rails' TimeWithZone, and made pretty p…
…rinting optional because it inserts newlines inside text contents (can invalidate e.g. atom documents).


XML Node

Example for generating xml:
  # Create an atom like document
  root = 'feed' do |feed|
    feed <<'id', ',2007:1')
    feed <<'title', 'Atom test feed')
    feed <<'author') do |author|
      author <<"name", "tobi")
      author <<"email", "")
    feed <<'entry') do |entry|
      entry <<'title', 'First post')
      entry <<'summary', 'Lorem ipsum', :type => 'xhtml')
      entry <<'created_at',
    feed <<'dc:published',
  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.