module XMLUtil

Module containing utility XML manipulation functions.

Module containing utility XML manipulation functions.

Public Class Methods

escape( xml ) click to toggle source

Trivially escape the XML string xml, by making the following substitutions:

  • & for &

  • < for &lt;

  • > for &gt;

Return the escaped XML string.

# File lib/ec2/amitools/xmlutil.rb, line 34
def XMLUtil::escape( xml )
  escaped_xml = xml.gsub( '&', '&amp;' )
  escaped_xml.gsub!( '<', '&lt;' )
  escaped_xml.gsub!( '>', '&gt;' )
  return escaped_xml
end
get_xml(xml_data, element_name) click to toggle source

Extract the string representation of the specified XML element name element_name from the XML string xml_data

# File lib/ec2/amitools/xmlutil.rb, line 18
def XMLUtil.get_xml(xml_data, element_name)
  start_tag = '<'+element_name+'>'
  end_tag = '</'+element_name+'>'
  return nil if (start_idx = xml_data.index(start_tag)).nil?
  return nil if (end_idx = xml_data.index(end_tag)).nil?
  end_idx += end_tag.size - 1
  xml_data[start_idx..end_idx]
end
unescape( escaped_xml ) click to toggle source

Trivially unescape the escaped XML string escaped_xml, by making the following substitutions:

  • &amp; for &

  • &lt; for <

  • &gt; for >

Return the XML string.

# File lib/ec2/amitools/xmlutil.rb, line 49
def XMLUtil::unescape( escaped_xml )
  xml = escaped_xml.gsub( '&lt;', '<' )
  xml.gsub!( '&gt;', '>' )
  xml.gsub!( '&amp;', '&' )
  return xml
end