Method: Atom::Text#xml
- Defined in:
- lib/atom/text.rb
#xml ⇒ Object
attempts to parse the content of this element as XML and return it as an array of REXML::Elements.
If self is “html” and Hpricot is installed, it will be converted to XHTML first.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/atom/text.rb', line 115 def xml xml = REXML::Element.new 'div' if self["type"] == "xhtml" @content.children.each { |child| xml << child } elsif self["type"] == "text" xml.text = self.to_s elsif self["type"] == "html" begin require "hpricot" rescue raise "Turning HTML content into XML requires Hpricot." end fixed = Hpricot(self.to_s, :xhtml_strict => true) xml = REXML::Document.new("<div>#{fixed}</div>").root else # Not XHTML, HTML, or text - return the REXML::Element, leave it up to the user to parse the content xml = @content end xml end |