Skip to content

Commit 22ad6c4

Browse files
authored
Merge pull request #14 from lexakimov/feature
0.7.0
2 parents 3ffe493 + 96a866c commit 22ad6c4

20 files changed

+466
-183
lines changed

CONFIGURATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ In the `value_override` sections, you can specify either a string value or speci
575575
| `source_filename` | Filename of the source XSD schema with its extension (e.g., `schema.xsd`). |
576576
| `source_extracted` | A string extracted from the source XSD filename using the regex specified in `source_filename`. |
577577
| `output_filename` | String defined by the `output_filename` configuration parameter. |
578+
| `root_element` | The name of the root element of the XML document. |
578579
| `uuid` | A random UUIDv4. |
579580
| `regex("pattern")` | A random string value matching the specified regular expression. |
580581
| `any('A', "B", C)` | A random value from the provided enumeration. |

CONFIGURATION_RU.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ xmlgenerator -c config.yml --pretty examples/order.xsd
229229

230230
Аналогично строкам, параметры `min_inclusive` и `max_inclusive` позволяют задать или сузить диапазон для числовых значений, если он определен в XSD.
231231

232-
Для демонстрации создадим XML по схеме [employee.xsd](examples/employee.xsd)
233-
В нашем примере это затронет поле `age`.
232+
Для демонстрации создадим XML по схеме [employee.xsd](examples/employee.xsd). В нашем примере это затронет поле `age`.
234233

235234
**Конфигурация `config.yml`:**
236235
```yaml
@@ -575,6 +574,7 @@ specific:
575574
| `source_filename` | Имя файла исходной xsd схемы с расширением (например `schema.xsd`) |
576575
| `source_extracted` | Строка, извлеченная из имени файла исходной xsd схемы регулярным выражением, указанным в `source_filename` |
577576
| `output_filename` | Строка, описываемая параметром конфигурации `output_filename` |
577+
| `root_element` | Название тега корневого элемента XML документа |
578578
| `uuid` | Случайный UUIDv4 |
579579
| `regex("pattern")` | Случайное строковое значение по указанному регулярному выражению |
580580
| `any('A', "B", C)` | Случайное значение из перечисленных |

README.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# XML Generator
22

3+
![PyPI - Version](https://img.shields.io/pypi/v/xmlgenerator)
4+
[![PyPI - Downloads](https://img.shields.io/pypi/dm/xmlgenerator)](https://pypistats.org/packages/xmlgenerator)
5+
[![DeepWiki](https://img.shields.io/badge/DeepWiki-lexakimov%2Fxmlgenerator-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==)](https://deepwiki.com/lexakimov/xmlgenerator)
6+
37
- [Русский 🇷🇺](README_RU.md)
48
- [English 🇺🇸](README.md)
59

@@ -44,27 +48,28 @@ The generator command is `xmlgenerator`
4448
**Flags and parameters:**
4549

4650
```
47-
usage: xmlgenerator [-h] [-c <config.yml>] [-o <output.xml>] [-p] [-v <validation>] [-ff] [-e <encoding>] [-s <seed>]
48-
[-d] [-V] [-C <shell>]
51+
usage: xmlgenerator [-h] [-c <config.yml>] [-o <output.xml>] [-p] [-n alias=namespace] [-v <validation>] [-ff]
52+
[-e <encoding>] [-s <seed>] [-d] [-V] [-C <shell>]
4953
xsd [xsd ...]
5054
5155
Generates XML documents from XSD schemas
5256
5357
positional arguments:
54-
xsd paths to xsd schema(s) or directory with xsd schemas
58+
xsd paths to xsd schema(s) or directory with xsd schemas
5559
5660
options:
57-
-h, --help show this help message and exit
58-
-c, --config <config.yml> pass a YAML configuration file
59-
-o, --output <output.xml> save the output to a directory or file
60-
-p, --pretty prettify the output XML
61-
-v, --validation <validation> validate the generated XML document (none, schema, schematron; default: schema)
62-
-ff, --fail-fast terminate execution on a validation error (default: true)
63-
-e, --encoding <encoding> the output XML encoding (utf-8, windows-1251; default: utf-8)
64-
-s, --seed <seed> set the randomization seed
65-
-d, --debug enable debug mode
66-
-V, --version show the current version
67-
-C, --completion <shell> print a shell completion script (bash, zsh, tcsh)
61+
-h, --help show this help message and exit
62+
-c, --config <config.yml> pass a YAML configuration file
63+
-o, --output <output.xml> save the output to a directory or file
64+
-p, --pretty prettify the output XML
65+
-n, --namespace alias=namespace define XML namespace alias (repeatable flag)
66+
-v, --validation <validation> validate the generated XML document (none, schema, schematron; default: schema)
67+
-ff, --fail-fast terminate execution on a validation error (default: true)
68+
-e, --encoding <encoding> the output XML encoding (utf-8, windows-1251; default: utf-8)
69+
-s, --seed <seed> set the randomization seed
70+
-d, --debug enable debug mode
71+
-V, --version show the current version
72+
-C, --completion <shell> print a shell completion script (bash, zsh, tcsh)
6873
```
6974

7075
**Examples:**
@@ -137,10 +142,9 @@ Contributions are welcome! Please open an issue or submit a pull request on GitH
137142

138143
4.1. **Install the package:**
139144

145+
Install in develop mode (code changes will be immediately reflected):
140146
```bash
141-
pip install .
142-
# or for development mode (code changes will be immediately reflected)
143-
# pip install -e .
147+
pip install -e .
144148
```
145149

146150
4.2. **Otherwise, build single executable:**
@@ -149,11 +153,6 @@ Contributions are welcome! Please open an issue or submit a pull request on GitH
149153
python build_native.py
150154
```
151155

152-
### Project Structure
153-
154-
- `xmlgenerator/` - main project code
155-
- `tests/` - tests
156-
157156
### Running Tests
158157

159158
```bash

README_RU.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# XML Generator
22

3+
![PyPI - Version](https://img.shields.io/pypi/v/xmlgenerator)
4+
[![PyPI - Downloads](https://img.shields.io/pypi/dm/xmlgenerator)](https://pypistats.org/packages/xmlgenerator)
5+
[![DeepWiki](https://img.shields.io/badge/DeepWiki-lexakimov%2Fxmlgenerator-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==)](https://deepwiki.com/lexakimov/xmlgenerator)
6+
37
- [Русский 🇷🇺](README_RU.md)
48
- [English 🇺🇸](README.md)
59

@@ -44,27 +48,28 @@ xmlgenerator -C bash | sudo tee /etc/bash_completion.d/xmlgenerator
4448
**Описание флагов и параметров запуска:**
4549

4650
```
47-
usage: xmlgenerator [-h] [-c <config.yml>] [-o <output.xml>] [-p] [-v <validation>] [-ff] [-e <encoding>] [-s <seed>]
48-
[-d] [-V] [-C <shell>]
51+
usage: xmlgenerator [-h] [-c <config.yml>] [-o <output.xml>] [-p] [-n alias=namespace] [-v <validation>] [-ff]
52+
[-e <encoding>] [-s <seed>] [-d] [-V] [-C <shell>]
4953
xsd [xsd ...]
5054
5155
Generates XML documents from XSD schemas
5256
5357
positional arguments:
54-
xsd paths to xsd schema(s) or directory with xsd schemas
58+
xsd paths to xsd schema(s) or directory with xsd schemas
5559
5660
options:
57-
-h, --help show this help message and exit
58-
-c, --config <config.yml> pass a YAML configuration file
59-
-o, --output <output.xml> save the output to a directory or file
60-
-p, --pretty prettify the output XML
61-
-v, --validation <validation> validate the generated XML document (none, schema, schematron; default: schema)
62-
-ff, --fail-fast terminate execution on a validation error (default: true)
63-
-e, --encoding <encoding> the output XML encoding (utf-8, windows-1251; default: utf-8)
64-
-s, --seed <seed> set the randomization seed
65-
-d, --debug enable debug mode
66-
-V, --version show the current version
67-
-C, --completion <shell> print a shell completion script (bash, zsh, tcsh)
61+
-h, --help show this help message and exit
62+
-c, --config <config.yml> pass a YAML configuration file
63+
-o, --output <output.xml> save the output to a directory or file
64+
-p, --pretty prettify the output XML
65+
-n, --namespace alias=namespace define XML namespace alias (repeatable flag)
66+
-v, --validation <validation> validate the generated XML document (none, schema, schematron; default: schema)
67+
-ff, --fail-fast terminate execution on a validation error (default: true)
68+
-e, --encoding <encoding> the output XML encoding (utf-8, windows-1251; default: utf-8)
69+
-s, --seed <seed> set the randomization seed
70+
-d, --debug enable debug mode
71+
-V, --version show the current version
72+
-C, --completion <shell> print a shell completion script (bash, zsh, tcsh)
6873
```
6974

7075
**Примеры:**
@@ -137,10 +142,9 @@ options:
137142

138143
4.1. **Установите пакет:**
139144

145+
Установка в режиме разработки (изменения в коде будут сразу видны):
140146
```bash
141-
pip install .
142-
# или для режима разработки (изменения в коде будут сразу видны)
143-
# pip install -e .
147+
pip install -e .
144148
```
145149

146150
4.2. **Или соберите единый исполняемый файл:**
@@ -149,11 +153,6 @@ options:
149153
python build_native.py
150154
```
151155

152-
### Структура проекта
153-
154-
- `xmlgenerator/` - основной код проекта
155-
- `tests/` - тесты
156-
157156
### Запуск тестов
158157

159158
```bash

requirements.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
lxml==5.3.1
2-
xmlschema==3.4.3
3-
Faker==37.0.0
1+
lxml==6.0.0
2+
xmlschema==4.1.0
3+
Faker==37.4.2
44
rstr==3.2.2
55
PyYAML==6.0.2
6-
shtab==1.7.1
6+
shtab==1.7.2
77

88
# dev
9-
pytest==8.3.5
10-
pytest-repeat
11-
setuptools==78.1.1
12-
nuitka
13-
twine
9+
pytest==8.4.1
10+
pytest-repeat==0.9.4
11+
setuptools==80.9.0
12+
nuitka==2.7.12
13+
twine==6.1.0

tests/data/namespaces/_base.xsd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
xmlns="urn://foo/base" targetNamespace="urn://foo/base"
4+
elementFormDefault="qualified">
5+
6+
<xsd:complexType name="PersonInfoBase">
7+
<xsd:sequence>
8+
<xsd:element name="lastName" type="String99"/>
9+
<xsd:element name="firstName" type="String49"/>
10+
<xsd:element name="middleName" type="String49" minOccurs="0"/>
11+
</xsd:sequence>
12+
</xsd:complexType>
13+
14+
<xsd:simpleType name="String49">
15+
<xsd:restriction base="xsd:string">
16+
<xsd:maxLength value="49"/>
17+
</xsd:restriction>
18+
</xsd:simpleType>
19+
20+
<xsd:simpleType name="String99">
21+
<xsd:restriction base="xsd:string">
22+
<xsd:maxLength value="99"/>
23+
</xsd:restriction>
24+
</xsd:simpleType>
25+
26+
</xsd:schema>

tests/data/namespaces/_commons.xsd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
xmlns:bs="urn://foo/base"
4+
xmlns="urn://foo/commons" targetNamespace="urn://foo/commons"
5+
elementFormDefault="qualified">
6+
7+
<xsd:import namespace="urn://foo/base" schemaLocation="_base.xsd"/>
8+
9+
<xsd:complexType name="MessageRoot">
10+
<xsd:sequence>
11+
<xsd:element name="personInfo" type="PersonInfo"/>
12+
</xsd:sequence>
13+
</xsd:complexType>
14+
15+
<xsd:complexType name="PersonInfo">
16+
<xsd:complexContent>
17+
<xsd:extension base="bs:PersonInfoBase">
18+
<xsd:sequence>
19+
<xsd:element name="birthDate" type="xsd:date"/>
20+
</xsd:sequence>
21+
</xsd:extension>
22+
</xsd:complexContent>
23+
</xsd:complexType>
24+
25+
</xsd:schema>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
xmlns:rc="urn://foo/commons"
4+
xmlns="urn://foo/custom" targetNamespace="urn://foo/custom"
5+
elementFormDefault="qualified">
6+
7+
<xsd:import namespace="urn://foo/commons" schemaLocation="_commons.xsd"/>
8+
9+
<xsd:element name="root" type="rc:MessageRoot"/>
10+
11+
</xsd:schema>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3+
xmlns:rc="urn://foo/commons"
4+
targetNamespace="urn://foo/custom"
5+
elementFormDefault="qualified">
6+
7+
<xsd:import namespace="urn://foo/commons" schemaLocation="_commons.xsd"/>
8+
9+
<xsd:element name="root" type="rc:MessageRoot"/>
10+
11+
</xsd:schema>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<schema xmlns="http://www.w3.org/2001/XMLSchema">
3+
<element name="root">
4+
<simpleType>
5+
<restriction base="positiveInteger">
6+
<enumeration value="1"/>
7+
</restriction>
8+
</simpleType>
9+
</element>
10+
</schema>

0 commit comments

Comments
 (0)