xmlgenerator 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xmlgenerator-0.1.0/LICENSE +21 -0
- xmlgenerator-0.1.0/PKG-INFO +314 -0
- xmlgenerator-0.1.0/README.md +285 -0
- xmlgenerator-0.1.0/setup.cfg +4 -0
- xmlgenerator-0.1.0/setup.py +31 -0
- xmlgenerator-0.1.0/xmlgenerator/__init__.py +0 -0
- xmlgenerator-0.1.0/xmlgenerator/arguments.py +138 -0
- xmlgenerator-0.1.0/xmlgenerator/bootstrap.py +73 -0
- xmlgenerator-0.1.0/xmlgenerator/configuration.py +135 -0
- xmlgenerator-0.1.0/xmlgenerator/generator.py +387 -0
- xmlgenerator-0.1.0/xmlgenerator/randomization.py +40 -0
- xmlgenerator-0.1.0/xmlgenerator/substitution.py +118 -0
- xmlgenerator-0.1.0/xmlgenerator/validation.py +52 -0
- xmlgenerator-0.1.0/xmlgenerator.egg-info/PKG-INFO +314 -0
- xmlgenerator-0.1.0/xmlgenerator.egg-info/SOURCES.txt +17 -0
- xmlgenerator-0.1.0/xmlgenerator.egg-info/dependency_links.txt +1 -0
- xmlgenerator-0.1.0/xmlgenerator.egg-info/entry_points.txt +2 -0
- xmlgenerator-0.1.0/xmlgenerator.egg-info/requires.txt +5 -0
- xmlgenerator-0.1.0/xmlgenerator.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Alexey Akimov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,314 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: xmlgenerator
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Generates XML documents from XSD schemas
|
5
|
+
Home-page: https://github.com/lexakimov/xmlgenerator
|
6
|
+
Author: Alexey Akimov
|
7
|
+
Author-email: lex.akimov23@gmail.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.6
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: lxml
|
15
|
+
Requires-Dist: xmlschema
|
16
|
+
Requires-Dist: Faker
|
17
|
+
Requires-Dist: rstr
|
18
|
+
Requires-Dist: PyYAML
|
19
|
+
Dynamic: author
|
20
|
+
Dynamic: author-email
|
21
|
+
Dynamic: classifier
|
22
|
+
Dynamic: description
|
23
|
+
Dynamic: description-content-type
|
24
|
+
Dynamic: home-page
|
25
|
+
Dynamic: license-file
|
26
|
+
Dynamic: requires-dist
|
27
|
+
Dynamic: requires-python
|
28
|
+
Dynamic: summary
|
29
|
+
|
30
|
+
# XML Generator
|
31
|
+
|
32
|
+
- [Русский 🇷🇺](README_RU.md)
|
33
|
+
- [English 🇺🇸](README.md)
|
34
|
+
|
35
|
+
Generates XML documents based on XSD schemas with the ability to customize data through a YAML configuration file.
|
36
|
+
Simplifies the creation of test or demonstration XML data for complex schemas.
|
37
|
+
|
38
|
+
## Features
|
39
|
+
|
40
|
+
- Generation of XML documents based on XSD schemas
|
41
|
+
- Customization of generated values via a YAML configuration file
|
42
|
+
- Validation of generated documents
|
43
|
+
- Command-line interface for convenient use
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
### Installation via pip
|
48
|
+
|
49
|
+
```bash
|
50
|
+
pip install xmlgenerator
|
51
|
+
```
|
52
|
+
|
53
|
+
### Build from source
|
54
|
+
|
55
|
+
1. **Clone the repository:**
|
56
|
+
```bash
|
57
|
+
git clone https://github.com/lexakimov/xmlgenerator.git
|
58
|
+
cd xmlgenerator
|
59
|
+
```
|
60
|
+
|
61
|
+
2. **Create and activate a virtual environment (recommended):**
|
62
|
+
```bash
|
63
|
+
python -m venv .venv
|
64
|
+
```
|
65
|
+
* **For Linux/macOS:**
|
66
|
+
```bash
|
67
|
+
source .venv/bin/activate
|
68
|
+
```
|
69
|
+
* **For Windows (Command Prompt/PowerShell):**
|
70
|
+
```bash
|
71
|
+
.\.venv\Scripts\activate
|
72
|
+
```
|
73
|
+
|
74
|
+
3. **Install dependencies:**
|
75
|
+
```bash
|
76
|
+
pip install -r requirements.txt
|
77
|
+
```
|
78
|
+
|
79
|
+
4.1. **Install the package:**
|
80
|
+
```bash
|
81
|
+
pip install .
|
82
|
+
# or for development mode (code changes will be immediately reflected)
|
83
|
+
# pip install -e .
|
84
|
+
```
|
85
|
+
|
86
|
+
4.2. **Otherwise, build single executable:**
|
87
|
+
```bash
|
88
|
+
python build_native.py
|
89
|
+
```
|
90
|
+
|
91
|
+
## CLI Usage
|
92
|
+
|
93
|
+
The main command to run the generator is `xmlgenerator`.
|
94
|
+
|
95
|
+
**Examples:**
|
96
|
+
|
97
|
+
- Generate XML from a single schema and print to console:
|
98
|
+
```bash
|
99
|
+
xmlgenerator path/to/your/schema.xsd
|
100
|
+
```
|
101
|
+
|
102
|
+
- Generate XML from all schemas in a directory and save to the `output` folder using a configuration file:
|
103
|
+
```bash
|
104
|
+
xmlgenerator -c config.yml -o output/ path/to/schemas/
|
105
|
+
```
|
106
|
+
|
107
|
+
- Generate XML from a specific schema, save to a file with pretty formatting and windows-1251 encoding:
|
108
|
+
```bash
|
109
|
+
xmlgenerator -o output.xml -p -e windows-1251 path/to/your/schema.xsd
|
110
|
+
```
|
111
|
+
|
112
|
+
- Generate XML with validation disabled:
|
113
|
+
```bash
|
114
|
+
xmlgenerator -v none path/to/your/schema.xsd
|
115
|
+
```
|
116
|
+
|
117
|
+
**Install shell completions:**
|
118
|
+
|
119
|
+
```shell
|
120
|
+
# also available: zsh, tcsh
|
121
|
+
xmlgenerator -C bash | sudo tee /etc/bash_completion.d/xmlgenerator
|
122
|
+
```
|
123
|
+
|
124
|
+
**Detailed CLI Usage:**
|
125
|
+
|
126
|
+
```
|
127
|
+
usage: xmlgenerator [-h] [-c <config.yml>] [-o <output.xml>] [-p] [-v <validation>] [-ff] [-e <encoding>]
|
128
|
+
[--seed <seed>] [-d] [-V]
|
129
|
+
xsd [xsd ...]
|
130
|
+
|
131
|
+
Generates XML documents from XSD schemas
|
132
|
+
|
133
|
+
positional arguments:
|
134
|
+
xsd paths to xsd schema(s) or directory with xsd schemas
|
135
|
+
|
136
|
+
options:
|
137
|
+
-h, --help show this help message and exit
|
138
|
+
-c, --config <config.yml> pass yaml configuration file
|
139
|
+
-o, --output <output.xml> save output to dir or file
|
140
|
+
-p, --pretty prettify output XML
|
141
|
+
-v, --validation <validation> validate generated XML document (none, schema, schematron, default is schema)
|
142
|
+
-ff, --fail-fast terminate execution on validation error (default is true)
|
143
|
+
-e, --encoding <encoding> output XML encoding (utf-8, windows-1251, default is utf-8)
|
144
|
+
--seed <seed> set randomization seed
|
145
|
+
-d, --debug enable debug mode
|
146
|
+
-V, --version shows current version
|
147
|
+
-C, --completion <shell> print shell completion script (bash, zsh, tcsh)
|
148
|
+
```
|
149
|
+
|
150
|
+
## Configuration
|
151
|
+
|
152
|
+
The generator can be configured using a YAML file passed via the `-c` or `--config` option.
|
153
|
+
|
154
|
+
**Configuration File Structure:**
|
155
|
+
|
156
|
+
```yaml
|
157
|
+
# Global settings (apply to all schemas)
|
158
|
+
global:
|
159
|
+
|
160
|
+
# Regular expression to extract a substring from the source xsd schema filename.
|
161
|
+
# The extracted substring can be used via the `source_extracted` function.
|
162
|
+
# The regular expression must contain the group `extracted`.
|
163
|
+
# Default value: `(?P<extracted>.*).(xsd|XSD)` (extracts the filename without extension).
|
164
|
+
source_filename: ...
|
165
|
+
|
166
|
+
# Filename template for saving the generated document.
|
167
|
+
# Default value: `{{ source_filename }}_{{ uuid }}` (xsd schema filename + random UUID)
|
168
|
+
output_filename: ...
|
169
|
+
|
170
|
+
# Random value generator settings
|
171
|
+
randomization:
|
172
|
+
# Probability of adding optional elements (0.0-1.0)
|
173
|
+
# Default value: 0.5
|
174
|
+
probability: 1
|
175
|
+
# Limit for the maximum number of elements
|
176
|
+
max_occurs: 5
|
177
|
+
# Minimum string length
|
178
|
+
min_length: 5
|
179
|
+
# Maximum string length
|
180
|
+
max_length: 20
|
181
|
+
# Minimum numeric value
|
182
|
+
min_inclusive: 10
|
183
|
+
# Maximum numeric value
|
184
|
+
max_inclusive: 1000000
|
185
|
+
|
186
|
+
# Override generated values for tags and attributes.
|
187
|
+
# Key - string or regular expression to match the tag/attribute name.
|
188
|
+
# Value - string with optional use of placeholders:
|
189
|
+
# `{{ function }}` - substitutes the value provided by the predefined function.
|
190
|
+
# `{{ function | modifier }}` - same, but with a modifier [ global | local ].
|
191
|
+
# - `global` - a single value will be used along all generation.
|
192
|
+
# - `local` - a single value will be used in context of current document.
|
193
|
+
#
|
194
|
+
# The list of available functions is below.
|
195
|
+
# The order of entries matters; the first matching override will be selected.
|
196
|
+
# Key matching is case-insensitive.
|
197
|
+
value_override:
|
198
|
+
name_regexp_1: "static value"
|
199
|
+
name_regexp_2: "{{ function_call }}"
|
200
|
+
"name_regexp_\d": "static-text-and-{{ function_call }}"
|
201
|
+
name: "static-text-and-{{ function_call }}-{{ another_function_call }}"
|
202
|
+
|
203
|
+
# Extend/override global settings for specific files.
|
204
|
+
# Key - string or regular expression to match the xsd filename(s).
|
205
|
+
# The order of entries matters; the first matching override will be selected.
|
206
|
+
# Key matching is case-insensitive.
|
207
|
+
specific:
|
208
|
+
# Each value can have the same set of parameters as the global section
|
209
|
+
"SCHEM.*":
|
210
|
+
# for schemas named "SCHEM.*", xml document names will only contain UUIDv4 + '.xml'
|
211
|
+
output_filename: "{{ uuid }}"
|
212
|
+
# Random value generator settings for schemas named "SCHEM.*"
|
213
|
+
randomization:
|
214
|
+
# for schemas named "SCHEM.*", the probability of adding optional elements will be 30%
|
215
|
+
probability: 0.3
|
216
|
+
value_override:
|
217
|
+
# override the value set by the global configuration
|
218
|
+
name_regexp_1: "static value"
|
219
|
+
# reset overrides for tags/attributes containing 'name' set by the global configuration
|
220
|
+
name:
|
221
|
+
```
|
222
|
+
|
223
|
+
Configuration Priority:
|
224
|
+
|
225
|
+
- specific settings
|
226
|
+
- global settings
|
227
|
+
- default settings
|
228
|
+
|
229
|
+
### Placeholder Functions
|
230
|
+
|
231
|
+
In the `value_override` sections, you can specify either a string value or special placeholders:
|
232
|
+
|
233
|
+
- `{{ function }}` - Substitutes the value provided by the predefined function.
|
234
|
+
- `{{ function | modifier }}` - Same, but with a modifier `[ global | local ]`, where:
|
235
|
+
- `global`: The function will generate and use *the same single value* throughout the *entire generation process*
|
236
|
+
for all documents.
|
237
|
+
- `local`: The function will generate and use *the same single value* within the scope of *a single generated
|
238
|
+
document*.
|
239
|
+
- No modifier: A new value is generated each time the function is called.
|
240
|
+
|
241
|
+
**List of Placeholder Functions:**
|
242
|
+
|
243
|
+
| Function | Description |
|
244
|
+
|------------------------------------|------------------------------------------------------------------------------------------------------------|
|
245
|
+
| `source_filename` | Filename of the source xsd schema with extension (e.g., `schema.xsd`) |
|
246
|
+
| `source_extracted` | String extracted from the source xsd filename using the regex specified in `source_filename_extract_regex` |
|
247
|
+
| `output_filename` | String described by the `output_filename_template` configuration parameter |
|
248
|
+
| `uuid` | Random UUIDv4 |
|
249
|
+
| `regex("pattern")` | Random string value matching the specified regular expression |
|
250
|
+
| `number(A, B)` | Random number between A and B |
|
251
|
+
| `date("2010-01-01", "2025-01-01")` | Random date within the specified range |
|
252
|
+
| `last_name` | Last Name |
|
253
|
+
| `first_name` | First Name |
|
254
|
+
| `middle_name` | Middle Name |
|
255
|
+
| `address_text` | Address |
|
256
|
+
| `administrative_unit` | Administrative Unit (e.g., District) |
|
257
|
+
| `house_number` | House Number |
|
258
|
+
| `city_name` | City Name |
|
259
|
+
| `postcode` | Postal Code |
|
260
|
+
| `company_name` | Company Name |
|
261
|
+
| `bank_name` | Bank Name |
|
262
|
+
| `phone_number` | Phone Number |
|
263
|
+
| `inn_fl` | Individual Taxpayer Number (Physical Person) |
|
264
|
+
| `inn_ul` | Taxpayer Identification Number (Legal Entity) |
|
265
|
+
| `ogrn_ip` | Primary State Registration Number (Individual Entrepreneur) |
|
266
|
+
| `ogrn_fl` | Primary State Registration Number (Physical Person) |
|
267
|
+
| `kpp` | Reason Code for Registration |
|
268
|
+
| `snils_formatted` | SNILS (Personal Insurance Account Number) in the format `123-456-789 90` |
|
269
|
+
|
270
|
+
**Configuration Examples:**
|
271
|
+
|
272
|
+
```yaml
|
273
|
+
# TODO Add configuration examples.
|
274
|
+
```
|
275
|
+
|
276
|
+
---
|
277
|
+
|
278
|
+
## Validation
|
279
|
+
|
280
|
+
Generated XML documents are checked for conformance against the schema used for generation.
|
281
|
+
By default, validation against the source XSD schema is used.
|
282
|
+
|
283
|
+
If a document does not conform to the schema, execution stops immediately.
|
284
|
+
This behavior can be disabled using the flag `-ff false` or `--fail-fast false`.
|
285
|
+
|
286
|
+
To disable validation, use the flag `-v none` or `--validation none`.
|
287
|
+
|
288
|
+
## Contribution
|
289
|
+
|
290
|
+
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
|
291
|
+
|
292
|
+
### Project Structure
|
293
|
+
|
294
|
+
- `xmlgenerator/` - main project code
|
295
|
+
- `tests/` - tests
|
296
|
+
|
297
|
+
### Running Tests
|
298
|
+
|
299
|
+
```bash
|
300
|
+
pytest
|
301
|
+
```
|
302
|
+
|
303
|
+
---
|
304
|
+
|
305
|
+
## License
|
306
|
+
|
307
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
308
|
+
|
309
|
+
## Contacts
|
310
|
+
|
311
|
+
For any questions or issues, please contact [lex.akimov23@gmail.com].
|
312
|
+
|
313
|
+
You can also create an [Issue on GitHub](https://github.com/lexakimov/xmlgenerator/issues) to report bugs or suggest
|
314
|
+
improvements.
|
@@ -0,0 +1,285 @@
|
|
1
|
+
# XML Generator
|
2
|
+
|
3
|
+
- [Русский 🇷🇺](README_RU.md)
|
4
|
+
- [English 🇺🇸](README.md)
|
5
|
+
|
6
|
+
Generates XML documents based on XSD schemas with the ability to customize data through a YAML configuration file.
|
7
|
+
Simplifies the creation of test or demonstration XML data for complex schemas.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- Generation of XML documents based on XSD schemas
|
12
|
+
- Customization of generated values via a YAML configuration file
|
13
|
+
- Validation of generated documents
|
14
|
+
- Command-line interface for convenient use
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
### Installation via pip
|
19
|
+
|
20
|
+
```bash
|
21
|
+
pip install xmlgenerator
|
22
|
+
```
|
23
|
+
|
24
|
+
### Build from source
|
25
|
+
|
26
|
+
1. **Clone the repository:**
|
27
|
+
```bash
|
28
|
+
git clone https://github.com/lexakimov/xmlgenerator.git
|
29
|
+
cd xmlgenerator
|
30
|
+
```
|
31
|
+
|
32
|
+
2. **Create and activate a virtual environment (recommended):**
|
33
|
+
```bash
|
34
|
+
python -m venv .venv
|
35
|
+
```
|
36
|
+
* **For Linux/macOS:**
|
37
|
+
```bash
|
38
|
+
source .venv/bin/activate
|
39
|
+
```
|
40
|
+
* **For Windows (Command Prompt/PowerShell):**
|
41
|
+
```bash
|
42
|
+
.\.venv\Scripts\activate
|
43
|
+
```
|
44
|
+
|
45
|
+
3. **Install dependencies:**
|
46
|
+
```bash
|
47
|
+
pip install -r requirements.txt
|
48
|
+
```
|
49
|
+
|
50
|
+
4.1. **Install the package:**
|
51
|
+
```bash
|
52
|
+
pip install .
|
53
|
+
# or for development mode (code changes will be immediately reflected)
|
54
|
+
# pip install -e .
|
55
|
+
```
|
56
|
+
|
57
|
+
4.2. **Otherwise, build single executable:**
|
58
|
+
```bash
|
59
|
+
python build_native.py
|
60
|
+
```
|
61
|
+
|
62
|
+
## CLI Usage
|
63
|
+
|
64
|
+
The main command to run the generator is `xmlgenerator`.
|
65
|
+
|
66
|
+
**Examples:**
|
67
|
+
|
68
|
+
- Generate XML from a single schema and print to console:
|
69
|
+
```bash
|
70
|
+
xmlgenerator path/to/your/schema.xsd
|
71
|
+
```
|
72
|
+
|
73
|
+
- Generate XML from all schemas in a directory and save to the `output` folder using a configuration file:
|
74
|
+
```bash
|
75
|
+
xmlgenerator -c config.yml -o output/ path/to/schemas/
|
76
|
+
```
|
77
|
+
|
78
|
+
- Generate XML from a specific schema, save to a file with pretty formatting and windows-1251 encoding:
|
79
|
+
```bash
|
80
|
+
xmlgenerator -o output.xml -p -e windows-1251 path/to/your/schema.xsd
|
81
|
+
```
|
82
|
+
|
83
|
+
- Generate XML with validation disabled:
|
84
|
+
```bash
|
85
|
+
xmlgenerator -v none path/to/your/schema.xsd
|
86
|
+
```
|
87
|
+
|
88
|
+
**Install shell completions:**
|
89
|
+
|
90
|
+
```shell
|
91
|
+
# also available: zsh, tcsh
|
92
|
+
xmlgenerator -C bash | sudo tee /etc/bash_completion.d/xmlgenerator
|
93
|
+
```
|
94
|
+
|
95
|
+
**Detailed CLI Usage:**
|
96
|
+
|
97
|
+
```
|
98
|
+
usage: xmlgenerator [-h] [-c <config.yml>] [-o <output.xml>] [-p] [-v <validation>] [-ff] [-e <encoding>]
|
99
|
+
[--seed <seed>] [-d] [-V]
|
100
|
+
xsd [xsd ...]
|
101
|
+
|
102
|
+
Generates XML documents from XSD schemas
|
103
|
+
|
104
|
+
positional arguments:
|
105
|
+
xsd paths to xsd schema(s) or directory with xsd schemas
|
106
|
+
|
107
|
+
options:
|
108
|
+
-h, --help show this help message and exit
|
109
|
+
-c, --config <config.yml> pass yaml configuration file
|
110
|
+
-o, --output <output.xml> save output to dir or file
|
111
|
+
-p, --pretty prettify output XML
|
112
|
+
-v, --validation <validation> validate generated XML document (none, schema, schematron, default is schema)
|
113
|
+
-ff, --fail-fast terminate execution on validation error (default is true)
|
114
|
+
-e, --encoding <encoding> output XML encoding (utf-8, windows-1251, default is utf-8)
|
115
|
+
--seed <seed> set randomization seed
|
116
|
+
-d, --debug enable debug mode
|
117
|
+
-V, --version shows current version
|
118
|
+
-C, --completion <shell> print shell completion script (bash, zsh, tcsh)
|
119
|
+
```
|
120
|
+
|
121
|
+
## Configuration
|
122
|
+
|
123
|
+
The generator can be configured using a YAML file passed via the `-c` or `--config` option.
|
124
|
+
|
125
|
+
**Configuration File Structure:**
|
126
|
+
|
127
|
+
```yaml
|
128
|
+
# Global settings (apply to all schemas)
|
129
|
+
global:
|
130
|
+
|
131
|
+
# Regular expression to extract a substring from the source xsd schema filename.
|
132
|
+
# The extracted substring can be used via the `source_extracted` function.
|
133
|
+
# The regular expression must contain the group `extracted`.
|
134
|
+
# Default value: `(?P<extracted>.*).(xsd|XSD)` (extracts the filename without extension).
|
135
|
+
source_filename: ...
|
136
|
+
|
137
|
+
# Filename template for saving the generated document.
|
138
|
+
# Default value: `{{ source_filename }}_{{ uuid }}` (xsd schema filename + random UUID)
|
139
|
+
output_filename: ...
|
140
|
+
|
141
|
+
# Random value generator settings
|
142
|
+
randomization:
|
143
|
+
# Probability of adding optional elements (0.0-1.0)
|
144
|
+
# Default value: 0.5
|
145
|
+
probability: 1
|
146
|
+
# Limit for the maximum number of elements
|
147
|
+
max_occurs: 5
|
148
|
+
# Minimum string length
|
149
|
+
min_length: 5
|
150
|
+
# Maximum string length
|
151
|
+
max_length: 20
|
152
|
+
# Minimum numeric value
|
153
|
+
min_inclusive: 10
|
154
|
+
# Maximum numeric value
|
155
|
+
max_inclusive: 1000000
|
156
|
+
|
157
|
+
# Override generated values for tags and attributes.
|
158
|
+
# Key - string or regular expression to match the tag/attribute name.
|
159
|
+
# Value - string with optional use of placeholders:
|
160
|
+
# `{{ function }}` - substitutes the value provided by the predefined function.
|
161
|
+
# `{{ function | modifier }}` - same, but with a modifier [ global | local ].
|
162
|
+
# - `global` - a single value will be used along all generation.
|
163
|
+
# - `local` - a single value will be used in context of current document.
|
164
|
+
#
|
165
|
+
# The list of available functions is below.
|
166
|
+
# The order of entries matters; the first matching override will be selected.
|
167
|
+
# Key matching is case-insensitive.
|
168
|
+
value_override:
|
169
|
+
name_regexp_1: "static value"
|
170
|
+
name_regexp_2: "{{ function_call }}"
|
171
|
+
"name_regexp_\d": "static-text-and-{{ function_call }}"
|
172
|
+
name: "static-text-and-{{ function_call }}-{{ another_function_call }}"
|
173
|
+
|
174
|
+
# Extend/override global settings for specific files.
|
175
|
+
# Key - string or regular expression to match the xsd filename(s).
|
176
|
+
# The order of entries matters; the first matching override will be selected.
|
177
|
+
# Key matching is case-insensitive.
|
178
|
+
specific:
|
179
|
+
# Each value can have the same set of parameters as the global section
|
180
|
+
"SCHEM.*":
|
181
|
+
# for schemas named "SCHEM.*", xml document names will only contain UUIDv4 + '.xml'
|
182
|
+
output_filename: "{{ uuid }}"
|
183
|
+
# Random value generator settings for schemas named "SCHEM.*"
|
184
|
+
randomization:
|
185
|
+
# for schemas named "SCHEM.*", the probability of adding optional elements will be 30%
|
186
|
+
probability: 0.3
|
187
|
+
value_override:
|
188
|
+
# override the value set by the global configuration
|
189
|
+
name_regexp_1: "static value"
|
190
|
+
# reset overrides for tags/attributes containing 'name' set by the global configuration
|
191
|
+
name:
|
192
|
+
```
|
193
|
+
|
194
|
+
Configuration Priority:
|
195
|
+
|
196
|
+
- specific settings
|
197
|
+
- global settings
|
198
|
+
- default settings
|
199
|
+
|
200
|
+
### Placeholder Functions
|
201
|
+
|
202
|
+
In the `value_override` sections, you can specify either a string value or special placeholders:
|
203
|
+
|
204
|
+
- `{{ function }}` - Substitutes the value provided by the predefined function.
|
205
|
+
- `{{ function | modifier }}` - Same, but with a modifier `[ global | local ]`, where:
|
206
|
+
- `global`: The function will generate and use *the same single value* throughout the *entire generation process*
|
207
|
+
for all documents.
|
208
|
+
- `local`: The function will generate and use *the same single value* within the scope of *a single generated
|
209
|
+
document*.
|
210
|
+
- No modifier: A new value is generated each time the function is called.
|
211
|
+
|
212
|
+
**List of Placeholder Functions:**
|
213
|
+
|
214
|
+
| Function | Description |
|
215
|
+
|------------------------------------|------------------------------------------------------------------------------------------------------------|
|
216
|
+
| `source_filename` | Filename of the source xsd schema with extension (e.g., `schema.xsd`) |
|
217
|
+
| `source_extracted` | String extracted from the source xsd filename using the regex specified in `source_filename_extract_regex` |
|
218
|
+
| `output_filename` | String described by the `output_filename_template` configuration parameter |
|
219
|
+
| `uuid` | Random UUIDv4 |
|
220
|
+
| `regex("pattern")` | Random string value matching the specified regular expression |
|
221
|
+
| `number(A, B)` | Random number between A and B |
|
222
|
+
| `date("2010-01-01", "2025-01-01")` | Random date within the specified range |
|
223
|
+
| `last_name` | Last Name |
|
224
|
+
| `first_name` | First Name |
|
225
|
+
| `middle_name` | Middle Name |
|
226
|
+
| `address_text` | Address |
|
227
|
+
| `administrative_unit` | Administrative Unit (e.g., District) |
|
228
|
+
| `house_number` | House Number |
|
229
|
+
| `city_name` | City Name |
|
230
|
+
| `postcode` | Postal Code |
|
231
|
+
| `company_name` | Company Name |
|
232
|
+
| `bank_name` | Bank Name |
|
233
|
+
| `phone_number` | Phone Number |
|
234
|
+
| `inn_fl` | Individual Taxpayer Number (Physical Person) |
|
235
|
+
| `inn_ul` | Taxpayer Identification Number (Legal Entity) |
|
236
|
+
| `ogrn_ip` | Primary State Registration Number (Individual Entrepreneur) |
|
237
|
+
| `ogrn_fl` | Primary State Registration Number (Physical Person) |
|
238
|
+
| `kpp` | Reason Code for Registration |
|
239
|
+
| `snils_formatted` | SNILS (Personal Insurance Account Number) in the format `123-456-789 90` |
|
240
|
+
|
241
|
+
**Configuration Examples:**
|
242
|
+
|
243
|
+
```yaml
|
244
|
+
# TODO Add configuration examples.
|
245
|
+
```
|
246
|
+
|
247
|
+
---
|
248
|
+
|
249
|
+
## Validation
|
250
|
+
|
251
|
+
Generated XML documents are checked for conformance against the schema used for generation.
|
252
|
+
By default, validation against the source XSD schema is used.
|
253
|
+
|
254
|
+
If a document does not conform to the schema, execution stops immediately.
|
255
|
+
This behavior can be disabled using the flag `-ff false` or `--fail-fast false`.
|
256
|
+
|
257
|
+
To disable validation, use the flag `-v none` or `--validation none`.
|
258
|
+
|
259
|
+
## Contribution
|
260
|
+
|
261
|
+
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
|
262
|
+
|
263
|
+
### Project Structure
|
264
|
+
|
265
|
+
- `xmlgenerator/` - main project code
|
266
|
+
- `tests/` - tests
|
267
|
+
|
268
|
+
### Running Tests
|
269
|
+
|
270
|
+
```bash
|
271
|
+
pytest
|
272
|
+
```
|
273
|
+
|
274
|
+
---
|
275
|
+
|
276
|
+
## License
|
277
|
+
|
278
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
279
|
+
|
280
|
+
## Contacts
|
281
|
+
|
282
|
+
For any questions or issues, please contact [lex.akimov23@gmail.com].
|
283
|
+
|
284
|
+
You can also create an [Issue on GitHub](https://github.com/lexakimov/xmlgenerator/issues) to report bugs or suggest
|
285
|
+
improvements.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
from setuptools import setup, find_packages
|
2
|
+
|
3
|
+
setup(
|
4
|
+
name='xmlgenerator',
|
5
|
+
version='0.1.0',
|
6
|
+
packages=find_packages(exclude=("tests", "tests.*")),
|
7
|
+
entry_points={
|
8
|
+
'console_scripts': [
|
9
|
+
'xmlgenerator=xmlgenerator.bootstrap:main'
|
10
|
+
],
|
11
|
+
},
|
12
|
+
install_requires=[
|
13
|
+
'lxml',
|
14
|
+
'xmlschema',
|
15
|
+
'Faker',
|
16
|
+
'rstr',
|
17
|
+
'PyYAML'
|
18
|
+
],
|
19
|
+
author='Alexey Akimov',
|
20
|
+
author_email='lex.akimov23@gmail.com',
|
21
|
+
description='Generates XML documents from XSD schemas',
|
22
|
+
long_description=open('README.md').read(),
|
23
|
+
long_description_content_type='text/markdown',
|
24
|
+
url='https://github.com/lexakimov/xmlgenerator',
|
25
|
+
classifiers=[
|
26
|
+
'Programming Language :: Python :: 3',
|
27
|
+
'License :: OSI Approved :: MIT License',
|
28
|
+
'Operating System :: OS Independent',
|
29
|
+
],
|
30
|
+
python_requires='>=3.6',
|
31
|
+
)
|
File without changes
|