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 +5 -5
- data/README.md +60 -6
- data/lib/xsd_model/elements/base_element.rb +6 -7
- data/lib/xsd_model/elements/import.rb +3 -1
- data/lib/xsd_model/elements/include.rb +3 -1
- data/lib/xsd_model/elements/schema.rb +6 -0
- data/lib/xsd_model/parser.rb +1 -1
- data/xsd_model.gemspec +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78eefc3199301e8ff68c5f5c02b79a8f37fbd9470e3d03caceaa8413e80b79e4
|
4
|
+
data.tar.gz: cf94bd3c8e147022aec2adff305a7f9d5ebd89866cb14d43251e6fb1cabea8af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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. [
|
7
|
+
2. [Usage](#usage)
|
10
8
|
5. [License](#license)
|
11
9
|
|
12
10
|
## About
|
13
11
|
|
14
|
-
|
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
|
-
|
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
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
@
|
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
|
@@ -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
|
data/lib/xsd_model/parser.rb
CHANGED
@@ -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)
|
data/xsd_model.gemspec
CHANGED
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.
|
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:
|
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
|
-
|
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
|