xml_schema_mapper 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/xml_schema_mapper/builder.rb +1 -1
- data/lib/xml_schema_mapper/version.rb +1 -1
- data/lib/xml_schema_mapper.rb +24 -22
- metadata +2 -2
@@ -113,7 +113,7 @@ module XmlSchemaMapper
|
|
113
113
|
if element.namespace
|
114
114
|
|
115
115
|
ns = find_namespace(element)
|
116
|
-
raise "prefix for namespace #{element.namespace.inspect} not found" unless ns
|
116
|
+
raise "prefix for namespace #{element.namespace.inspect} not found. element: #{element.inspect}" unless ns
|
117
117
|
|
118
118
|
document.root.add_namespace(ns.prefix, ns.href)
|
119
119
|
end
|
data/lib/xml_schema_mapper.rb
CHANGED
@@ -45,8 +45,8 @@ module XmlSchemaMapper
|
|
45
45
|
|
46
46
|
def annonymus_type(name)
|
47
47
|
raise(%Q{call "schema 'path/to/your/File.xsd'" before calling "type"}) unless _schema
|
48
|
-
path
|
49
|
-
type
|
48
|
+
path = name.split('::')
|
49
|
+
type = _schema.types[path.shift]
|
50
50
|
self._type = path.map do |n|
|
51
51
|
type = type.elements[n].type if type
|
52
52
|
end.last
|
@@ -55,13 +55,13 @@ module XmlSchemaMapper
|
|
55
55
|
def parse(string_or_node)
|
56
56
|
return if string_or_node.nil?
|
57
57
|
case string_or_node
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
when String
|
59
|
+
string = File.exist?(string_or_node) ? File.read(string_or_node) : string_or_node
|
60
|
+
XmlSchemaMapper::Parser.new(self).parse(string)
|
61
|
+
when Nokogiri::XML::Node
|
62
|
+
XmlSchemaMapper::Parser.new(self).parse(string_or_node)
|
63
|
+
else
|
64
|
+
raise(ArgumentError, "param must be a String or Nokogiri::XML::Node, but \"#{string_or_node.inspect}\" given")
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -123,34 +123,36 @@ module XmlSchemaMapper
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def elements
|
126
|
-
type.elements.values.inject({
|
126
|
+
type.elements.values.inject({}) do |hash, element|
|
127
127
|
hash.merge element.name.underscore.to_sym => send(element.name.underscore.to_sym)
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
def to_xml(options = {
|
132
|
-
xml_document.root.to_xml({
|
131
|
+
def to_xml(options = {})
|
132
|
+
xml_document.root.to_xml({:encoding => 'UTF-8'}.merge(options))
|
133
133
|
end
|
134
134
|
|
135
135
|
def xml_document
|
136
136
|
document = XmlSchemaMapper::Builder.create_document(_type)
|
137
|
+
document.root.namespace = root_namespace
|
137
138
|
|
138
|
-
|
139
|
-
document.root.namespace = document.root.add_namespace_definition(ns.prefix, ns.href)
|
140
|
-
|
141
|
-
builder = XmlSchemaMapper::Builder.new(self, document.root, namespace_resolver)
|
139
|
+
builder = XmlSchemaMapper::Builder.new(self, document.root, namespace_resolver)
|
142
140
|
builder.build
|
143
141
|
builder.document
|
144
142
|
end
|
145
143
|
|
144
|
+
def root_namespace
|
145
|
+
namespaces = namespace_resolver || schema.namespaces
|
146
|
+
ns = namespaces.find_by_href (global_element || _type).namespace
|
147
|
+
document.root.add_namespace_definition(ns.prefix, ns.href)
|
148
|
+
end
|
149
|
+
|
146
150
|
def namespace_resolver
|
147
151
|
case
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
else
|
153
|
-
schema.namespaces
|
152
|
+
when self.class.namespace_resolver_class
|
153
|
+
self.class.namespace_resolver_class.new(schema.namespaces)
|
154
|
+
when XmlSchemaMapper.namespace_resolver_class
|
155
|
+
XmlSchemaMapper.namespace_resolver_class.new(schema.namespaces)
|
154
156
|
end
|
155
157
|
end
|
156
158
|
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: xml_schema_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Anton Sozontov
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|