cdm_data_loaders.converters.readers.xsd ¶
Read XML Schema Definition (XSD) documents into the converter IR.
XsdReader
dataclass
¶
Build typed converter IR documents from XML Schema Definition (XSD) files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_tag
|
str | None
|
Default target XML element tag name when not supplied to :meth: |
None
|
max_recursion_depth
|
int
|
Maximum times a recursive |
DEFAULT_MAX_RECURSION_DEPTH
|
error_type
|
type[ConversionError]
|
Base exception class raised when a construct cannot be converted. |
ConversionError
|
error_by_code
|
Mapping[str, type[ConversionError]]
|
Mapping from specification error code ( |
frozendict()
|
Source code in src/cdm_data_loaders/converters/readers/xsd.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 | |
__post_init__ ¶
read ¶
read(
source: XMLSchema | str | Path,
xml_tag: str | None = None,
*,
struct_cache: dict[tuple[int, bool], Any] | None = None
) -> SchemaDocument
Read an xmlschema.XMLSchema element into a SchemaDocument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
XMLSchema | str | Path
|
Loaded |
required |
xml_tag
|
str | None
|
Target XML element name (local name or Clark notation). Defaults to |
None
|
struct_cache
|
dict[tuple[int, bool], Any] | None
|
Optional cache sharing IR struct |
None
|
Returns:
| Type | Description |
|---|---|
SchemaDocument
|
Structural IR document with |
Raises:
| Type | Description |
|---|---|
ConversionError
|
If the schema or |
Source code in src/cdm_data_loaders/converters/readers/xsd.py
read_at_level ¶
read_at_level(
source: XMLSchema | str | Path,
level: int,
*,
root_tag: str | None = None
) -> dict[str, SchemaDocument]
Read all XML element types at depth level in an XSD schema into SchemaDocuments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
XMLSchema | str | Path
|
Loaded |
required |
level
|
int
|
Non-negative depth relative to the root element(s). |
required |
root_tag
|
str | None
|
Optional explicit root element name to anchor the traversal. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, SchemaDocument]
|
Mapping of element local tag name to its |
Source code in src/cdm_data_loaders/converters/readers/xsd.py
load_schema ¶
Load an XML schema document into an XMLSchema object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_path
|
str | Path
|
path to the schema file |
required |
Returns:
| Type | Description |
|---|---|
xmlschema.XMLSchema
|
loaded schema |
Source code in src/cdm_data_loaders/converters/readers/xsd.py
resolve_root_elements ¶
resolve_root_elements(
schema: XMLSchema,
root_tag: str | None = None,
*,
error_type: type[ConversionError] = ConversionError,
error_by_code: Mapping[
str, type[ConversionError]
] = frozendict()
) -> list[XsdElement]
Resolve the level-0 root XsdElement declarations in an XSD schema.
When root_tag is omitted, root elements are deduced as global <xs:element> declarations
that are not referenced as child elements inside any other complex type's content model (falling
back to all global elements if all global elements participate in a mutual reference cycle).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema
|
loaded XMLSchema instance |
required |
root_tag
|
str | None
|
optional explicit root element name (local name or Clark notation) |
None
|
error_type
|
type[ConversionError]
|
fallback exception class |
ConversionError
|
error_by_code
|
Mapping[str, type[ConversionError]]
|
mapping of specification error codes to exception classes |
frozendict()
|
Returns:
| Type | Description |
|---|---|
list[XsdElement]
|
list of root XsdElement declarations in schema order |
Source code in src/cdm_data_loaders/converters/readers/xsd.py
resolve_elements_at_level ¶
resolve_elements_at_level(
schema: XMLSchema,
level: int,
*,
root_tag: str | None = None,
error_type: type[ConversionError] = ConversionError,
error_by_code: Mapping[
str, type[ConversionError]
] = frozendict()
) -> dict[str, XsdElement]
Deduce all XsdElement declarations that can appear at depth level in an XSD schema.
Depth 0 corresponds to the root element(s); depth 1 corresponds to direct children of
the root element(s); depth 2 corresponds to grandchildren of the root element(s), and so on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema
|
loaded XMLSchema instance |
required |
level
|
int
|
non-negative depth relative to the root element(s) |
required |
root_tag
|
str | None
|
optional explicit root element name to anchor the traversal |
None
|
error_type
|
type[ConversionError]
|
fallback exception class |
ConversionError
|
error_by_code
|
Mapping[str, type[ConversionError]]
|
mapping of specification error codes to exception classes |
frozendict()
|
Returns:
| Type | Description |
|---|---|
dict[str, XsdElement]
|
mapping of element local tag name to its validated XsdElement declaration at |