lib/x12/xmldefinitions.rb in pd_x12-1.4.8 vs lib/x12/xmldefinitions.rb in pd_x12-1.5.0
- old
+ new
@@ -20,24 +20,22 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#++
#
-require "rexml/document"
module X12
-
- # $Id: XMLDefinitions.rb 90 2009-05-13 19:51:27Z ikk $
#
# A class for parsing X12 message definition expressed in XML format.
-
+ #
+
class XMLDefinitions < Hash
# Parse definitions out of XML file
def initialize(str)
- doc = REXML::Document.new(str)
- definitions = doc.root.name =~ /^Definition$/i ? doc.root.elements.to_a : [doc.root]
+ doc = LibXML::XML::Document.string(str)
+ definitions = doc.root.name =~ /^Definition$/i ? doc.root.find('*').to_a : [doc.root]
definitions.each { |element|
#puts element.name
syntax_element = case element.name
when /table/i
@@ -128,38 +126,38 @@
end # parse_field
def parse_table(e)
name, min, max, type, required, validation = parse_attributes(e)
- content = e.get_elements("Entry").inject({}) {|t, entry|
+ content = e.find("Entry").inject({}) {|t, entry|
t[entry.attributes["name"]] = entry.attributes["value"]
t
}
Table.new(name, content)
end
def parse_segment(e)
name, min, max, type, required, validation = parse_attributes(e)
- fields = e.get_elements("Field").inject([]) {|f, field|
+ fields = e.find("Field").inject([]) {|f, field|
f << parse_field(field)
}
Segment.new(name, fields, Range.new(min, max))
end
def parse_composite(e)
name, min, max, type, required, validation = parse_attributes(e)
- fields = e.get_elements("Field").inject([]) {|f, field|
+ fields = e.find("Field").inject([]) {|f, field|
f << parse_field(field)
}
Composite.new(name, fields)
end
def parse_loop(e)
name, min, max, type, required, validation = parse_attributes(e)
- components = e.elements.to_a.inject([]){|r, element|
+ components = e.find('*').to_a.inject([]){|r, element|
r << case element.name
when /loop/i
parse_loop(element)
when /segment/i
parse_segment(element)