XML Schema Libraries#
A SchemaLibrary is a project-level asset that holds one or more XSD or JSON schema files defining XML document structures. Schema libraries are used by the Hierarchical Data stage to parse and validate XML data.
A library is created once and can be referenced by multiple Hierarchical Data stages across many flows within the same project.
Creating a Schema Library#
To create a schema library, use the Project.create_schema_library() method:
>>> schema_lib = project.create_schema_library(
... name='plant_collection',
... description='XSD for plant collection XML documents'
... )
Uploading a Schema File#
After creating the library, upload an XSD or JSON schema file using SchemaLibrary.upload_schema_file(). Supported extensions are .xsd, .json, .jsn, and .jsd.
>>> from pathlib import Path
>>> response = schema_lib.upload_schema_file(
... project=project,
... file=Path('plant_collection.xsd')
... )
The file is automatically wrapped in a zip archive before being sent to the platform. After upload, the library’s parse_status field reflects whether the schema was parsed successfully.
Attaching a Schema Library to a Stage#
To use a schema library in a Hierarchical Data stage, attach it using HierarchicalDataStage.add_schema_library():
>>> flow = project.create_flow(name='xml_processing_flow', flow_type='batch')
>>> stage = flow.add_stage('Hierarchical Data', 'hierarchical_data')
>>> stage.add_schema_library(schema_lib)
Duplicate entries are silently ignored — adding the same library twice has no effect. To detach a library, use HierarchicalDataStage.remove_schema_library():
>>> stage.remove_schema_library(schema_lib)
After modifying the stage, persist the flow:
>>> project.update_flow(flow)
<Response [200]>
Retrieving Schema Libraries#
To list all schema libraries in a project, use the Project.schema_libraries property, which returns a SchemaLibraries collection:
>>> project.schema_libraries
[SchemaLibrary(library_id='...', name='plant_collection')]
Deleting a Schema Library#
To delete a schema library, use the Project.delete_schema_library() method:
>>> project.delete_schema_library(schema_lib)
<Response [204]>
Note
Schema libraries are project-level assets, independent of any flow. Deleting a library does not automatically remove references to it from existing Hierarchical Data stages.
See also
SchemaLibrary- API reference for SchemaLibrary classHierarchicalDataStage- API reference for HierarchicalDataStage class