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 <
-
> for >
Return the escaped XML string.
# File lib/ec2/amitools/xmlutil.rb, line 34 def XMLUtil::escape( xml ) escaped_xml = xml.gsub( '&', '&' ) escaped_xml.gsub!( '<', '<' ) escaped_xml.gsub!( '>', '>' ) 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:
-
& for &
-
< for <
-
> for >
Return the XML string.
# File lib/ec2/amitools/xmlutil.rb, line 49 def XMLUtil::unescape( escaped_xml ) xml = escaped_xml.gsub( '<', '<' ) xml.gsub!( '>', '>' ) xml.gsub!( '&', '&' ) return xml end