Class: RXSD::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rxsd/parser.rb

Overview

Provides class methods to parse xsd and xml data

Class Method Summary collapse

Class Method Details

.is_builtin?(builtin_class) ⇒ Boolean

Return true is specified class is builtin, else false

Returns:



50
51
52
# File 'lib/rxsd/parser.rb', line 50

def self.is_builtin?(builtin_class)
  [Array, String, Boolean, Char, Time, XSDFloat, XSDInteger].include? builtin_class
end

.parse_builtin_type(builtin_type_name) ⇒ Object

Return ruby class corresponding to builtin type



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/rxsd/parser.rb', line 55

def self.parse_builtin_type(builtin_type_name)
  res = nil

  case builtin_type_name
    when "xs:string" then
      res = String
    when "xs:boolean" then
      res = Boolean
    when "xs:decimal" then
      res = XSDFloat
    when "xs:float" then
      res = XSDFloat
    when "xs:double" then
      res = XSDFloat
    when "xs:duration" then
    when "xs:dateTime" then
      res = Time
    when "xs:date" then
      res = Time
    when "xs:gYearMonth" then
      res = Time
    when "xs:gYear" then
      res = Time
    when "xs:gMonthDay" then
      res = Time
    when "xs:gDay" then
      res = Time
    when "xs:gMonth" then
      res = Time
    when "xs:hexBinary" then
    when "xs:base64Binary" then
    when "xs:anyURI" then
    when "xs:QName" then
    when "xs:NOTATION" then
    when "xs:normalizedString"
    when "xs:token"
       res = String # FIXME should be a string derived class, eliminating whitespace
    when "xs:language"
    when "xs:NMTOKEN"
    when "xs:NMTOKENS"
    when "xs:Name"
    when "xs:NCName"
    when "xs:ID"
    when "xs:IDREF"
    when "xs:IDREFS"
    when "xs:ENTITY"
    when "xs:ENTITIES"
    when "xs:integer"
       res = XSDInteger
    when "xs:nonPositiveInteger"
       res = XSDInteger
    when "xs:negativeInteger"
       res = XSDInteger
    when "xs:long"
       res = XSDInteger
    when "xs:int"
       res = XSDInteger
    when "xs:short"
       res = XSDInteger
    when "xs:byte"
       res = Char
    when "xs:nonNegativeInteger"
       res = XSDInteger
    when "xs:unsignedLong"
       res = XSDInteger
    when "xs:unsignedInt"
       res = XSDInteger
    when "xs:unsignedShort"
       res = XSDInteger
    when "xs:unsignedByte"
       res = Char
    when "xs:positiveInteger"
       res = XSDInteger
  end

  return res
end

.parse_xml(args) ⇒ Object

Parse xml specified by uri or in raw data form into RXSD::XSD::SchemaInstance instance



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rxsd/parser.rb', line 37

def self.parse_xml(args)
   data = Loader.load(args[:uri]) unless args[:uri].nil?
   data = args[:raw]              unless args[:raw].nil?
   Logger.debug "parsing xml"

   root_xml_node = XML::Node.factory :backend => :libxml, :xml => data
   schema_instance = SchemaInstance.new :builders => SchemaInstance.builders_from_xml(root_xml_node)

   Logger.debug "xml parsing complete"
   return schema_instance
end

.parse_xsd(args) ⇒ Object

Parse xsd specified by uri or in raw data form into RXSD::XSD::Schema instance args should be a hash w/ optional keys:

  • :uri location which to load resource from

  • :raw raw data which to parse



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rxsd/parser.rb', line 20

def self.parse_xsd(args)
   data = Loader.load(args[:uri]) unless args[:uri].nil?
   data = args[:raw]              unless args[:raw].nil?
   Logger.debug "parsing xsd"

   # FIXME validate against xsd's own xsd
   root_xml_node = XML::Node.factory :backend => :libxml, :xml => data
   schema = XSD::Schema.from_xml root_xml_node

   Logger.debug "parsed xsd, resolving relationships"
   Resolver.resolve_nodes schema

   Logger.debug "xsd parsing complete"
   return schema
end