xsd_model 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 804d3f69f695bf3916304c9da3b0d8c443353b0e
4
- data.tar.gz: e2370ef66bf2977e7dc4be65f01fe5b9010efd5d
2
+ SHA256:
3
+ metadata.gz: 78eefc3199301e8ff68c5f5c02b79a8f37fbd9470e3d03caceaa8413e80b79e4
4
+ data.tar.gz: cf94bd3c8e147022aec2adff305a7f9d5ebd89866cb14d43251e6fb1cabea8af
5
5
  SHA512:
6
- metadata.gz: 1d0eb4bf82bba8439bfa36f847572a092f9dba3ecf449eeb697a6b28ea5a9dae7ca81dd711172eabdc7fc95062d1c2b7db9a7e2c4dd7291877b17b909e9c702d
7
- data.tar.gz: 66748ca9aa4cbe7218d5f95ec658495b1fdb5a5bf38889369e7b0df923f0d570804ee5734a1be0db59512311102892ba336e479deef28403f30445aa2bec592a
6
+ metadata.gz: 45afad446b42ebac359a2094bacba94e6ff44f977884e37421ce512f4787e9fab0d11597cc85ed275df4f96a3b707cf856b868f14b7b94478544cf675326e0c8
7
+ data.tar.gz: e35713ed455f837308d74297ed294b30dfb251b6d607267c173552a0a6045c6ee261208f417cf01fb1183b5a7447589b1851923080af7a60d6152bed1f09d32d
data/README.md CHANGED
@@ -1,20 +1,74 @@
1
1
  # XsdModel [![Build Status](https://travis-ci.org/Masa331/xsd_model.svg?branch=master)](https://travis-ci.org/Masa331/xsd_model)
2
2
 
3
- *Note that this can be unstable until 1.0.0*
4
-
5
- Takes a XSD string and parses it into a tree structure of nodes. A lot similar to Nokogiri but with few more useful methods.
3
+ Schema Definition (XSD) parser.
6
4
 
7
5
  Content:
8
6
  1. [About](#about)
9
- 2. [Api](#api)
7
+ 2. [Usage](#usage)
10
8
  5. [License](#license)
11
9
 
12
10
  ## About
13
11
 
14
- This gem provides a parser which takes XSD in a string and outputs tree structure of objects much like Nokogiri(which is internally used for parsing) does with XML. Each returned object represents one specific XSD core element and implements specific API to simplify the work with XSD. As it's written under the top heading, the API can be unstable until 1.0.0 and might miss some core XSD elements, attribute accessors, etc.
12
+ XsdModel parses a XML Schema Definition (XSD) and returns tree structure of objects representing XSD nodes. Each object implements specific API simplify the work with XSD.
13
+
14
+ ## Usage
15
+
16
+ ### Basics
17
+
18
+ Suppose you have following schema in a schema.xsd file:
19
+ ```
20
+ <?xml version="1.0"?>
21
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
22
+
23
+ <xs:element name="note">
24
+ <xs:complexType>
25
+ <xs:sequence>
26
+ <xs:element name="to" type="xs:string"/>
27
+ <xs:element name="from" type="xs:string"/>
28
+ <xs:element name="heading" type="xs:string"/>
29
+ <xs:element name="body" type="xs:string"/>
30
+ </xs:sequence>
31
+ </xs:complexType>
32
+ </xs:element>
33
+
34
+ </xs:schema>
35
+ ```
15
36
 
16
- ## Api
37
+ To parse it:
38
+ ```
39
+ require('xsd_model')
40
+ raw = File.read('schema.xsd')
41
+ xsd = XsdModel.parse(raw)
42
+ #=> #<XsdModel::Elements::Document:0x000056471a3b7cb8
43
+ #@children=
44
+ # [#<XsdModel::Elements::Schema:0x000056471a4659a8
45
+ # @children=
46
+ # [#<XsdModel::Elements::Text:0x000056471a4307d0>,
47
+ # #<XsdModel::Elements::Element:0x000056471a400dc8
48
+ # @children=
49
+ # [#<XsdModel::Elements::Text:0x000056471a3b3898>,
50
+ # #<XsdModel::Elements::ComplexType:0x000056471a403668
51
+ # @children=
52
+ # [#<XsdModel::Elements::Text:0x000056471a3b2a10>,
53
+ # #<XsdModel::Elements::Sequence:0x000056471a3d8ff8
54
+ # @children=
55
+ # [#<XsdModel::Elements::Text:0x000056471a3b19f8>,
56
+ # #<XsdModel::Elements::Element:0x000056471a3b0cd8>,
57
+ # #<XsdModel::Elements::Text:0x000056471a3c71b8>,
58
+ # #<XsdModel::Elements::Element:0x000056471a3c62b8>,
59
+ # #<XsdModel::Elements::Text:0x000056471a3c54f8>,
60
+ # #<XsdModel::Elements::Element:0x000056471a3c47b0>,
61
+ # #<XsdModel::Elements::Text:0x000056471a3dbaa0>,
62
+ # #<XsdModel::Elements::Element:0x000056471a3da830>,
63
+ # #<XsdModel::Elements::Text:0x000056471a3d9930>]>,
64
+ # #<XsdModel::Elements::Text:0x000056471a403cf8>]>,
65
+ # #<XsdModel::Elements::Text:0x000056471a4014a8>]>,
66
+ # #<XsdModel::Elements::Text:0x000056471a4660b0>],
67
+ # >],
68
+ #>
69
+ ```
17
70
 
71
+ ### TODO
18
72
  * basic parsing
19
73
  * ignore option
20
74
  * collect only option
@@ -9,15 +9,14 @@ module XsdModel
9
9
 
10
10
  XSD_URI = 'http://www.w3.org/2001/XMLSchema'
11
11
 
12
- attr_accessor :children, :attributes, :namespaces
12
+ attr_accessor :children, :attributes, :namespaces, :css_path
13
13
  attribute_method :name, :type, :ref
14
14
 
15
- def initialize(*args)
16
- hashes, rest = args.partition { |arg| arg.is_a? Hash }
17
-
18
- @children = rest.flatten
19
- @attributes = hashes[0] || {}
20
- @namespaces = hashes[1] || {}
15
+ def initialize(*args, attributes: {}, namespaces: {}, css_path: '')
16
+ @children = args.flatten
17
+ @attributes = attributes
18
+ @namespaces = namespaces
19
+ @css_path = css_path
21
20
  end
22
21
 
23
22
  def xmlns_prefix
@@ -10,7 +10,9 @@ module XsdModel
10
10
  def load(options = {})
11
11
  xml_string = File.read(schema_location)
12
12
 
13
- XsdModel.parse(xml_string, options).schema
13
+ schema = XsdModel.parse(xml_string, options).schema
14
+ schema.source = schema_location
15
+ schema
14
16
  end
15
17
  end
16
18
  end
@@ -10,7 +10,9 @@ module XsdModel
10
10
  def load(options = {})
11
11
  xml_string = File.read(schema_location)
12
12
 
13
- XsdModel.parse(xml_string, options).schema
13
+ schema = XsdModel.parse(xml_string, options).schema
14
+ schema.source = schema_location
15
+ schema
14
16
  end
15
17
  end
16
18
  end
@@ -4,8 +4,14 @@ module XsdModel
4
4
  include BaseElement
5
5
  extend AttributeMethods
6
6
 
7
+ attr_accessor :source
7
8
  attribute_method 'targetNamespace'
8
9
 
10
+ def initialize(*args, attributes: {}, namespaces: {}, css_path: '')
11
+ super
12
+ @source = '(initial)'
13
+ end
14
+
9
15
  def collect_imported_schemas(options = {})
10
16
  _collect_imported_schemas(self, options)
11
17
  end
@@ -29,7 +29,7 @@ module XsdModel
29
29
  attributes = node.attributes.transform_values(&:value)
30
30
  namespaces = node.namespaces
31
31
 
32
- klass.new(children, attributes, namespaces)
32
+ klass.new(children, attributes: attributes, namespaces: namespaces, css_path: node.css_path)
33
33
  end
34
34
 
35
35
  def collect_children(node)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'xsd_model'
7
- spec.version = '0.6.0'
7
+ spec.version = '0.7.0'
8
8
  spec.authors = ['Premysl Donat']
9
9
  spec.email = ['pdonat@seznam.cz']
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xsd_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Premysl Donat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2019-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -182,8 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  requirements: []
185
- rubyforge_project:
186
- rubygems_version: 2.6.14.1
185
+ rubygems_version: 3.0.3
187
186
  signing_key:
188
187
  specification_version: 4
189
188
  summary: XSD parser