A deterministic transformer that converts Ampla Project XML into an ISA‑95 B2MML V0600 Equipment model.
The system replaces the legacy XSLT pipeline with a structured Python implementation.
Outputs:
- B2MML V0600 XML
- JSON model
- Excel workbook
- CSV exports
- HTML report
Tools:
- CLI
- FastAPI service
- Validation
- Diff engine
- Statistics
The project includes a full regression suite.
Ampla XML contains:
- equipment hierarchy
- equipment classes
- inheritance
- class and instance properties
The transformer produces:
- B2MML V0600 Equipment XML
- normalized internal model
- export formats for reporting and auditing
The system also reports:
- unmapped types
- unknown class IDs
- structural violations
- missing or malformed data
The core component is:
from app.transformers.ampla_to_b2mml import AmplaTransformer- Build class ID lookup
- Extract classes
- Compute inheritance chains
- Parse equipment tree
- Resolve full names
- Merge class and instance properties
- Normalize datatypes
- Normalize units of measure
- Sort and finalize model
The result is a stable internal representation used by all builders.
classDiagram
class Equipment {
+id: String
+name: String
+level: String
+class_ids: List
+children: List
+overrides: Dict
+properties: List
+full_name: String
}
class EquipmentClass {
+name: String
+parent: String
+properties: List
+inheritance_chain: List
}
class ClassProperty {
+name: String
+value: Any
+datatype: String
+unit_of_measure: String
}
class EquipmentProperty {
+name: String
+value: Any
+datatype: String
+unit_of_measure: String
+normalized_unit_of_measure: String
+raw_unit_of_measure: String
+uom_warning: String
+children: List
+attributes: Dict
}
Equipment "1" *-- "many" Equipment : children
Equipment "1" *-- "many" EquipmentProperty : properties
EquipmentClass "1" *-- "many" ClassProperty : properties
Equipment ..> EquipmentClass : inherits
sequenceDiagram
participant XML as Ampla XML
participant T as Transformer
participant M as Model
T->>XML: Class ID lookup
T->>XML: Class extraction
T->>XML: Inheritance resolution
T->>XML: Equipment parsing
T->>M: Property merge
T->>M: Datatype normalization
T->>M: UoM normalization
Configuration is stored in:
config/mapping.toml
Example:
[level_map]
"Citect.Ampla.Isa95.EnterpriseFolder" = "Enterprise"
"Citect.Ampla.Isa95.SiteFolder" = "Site"
"Citect.Ampla.Isa95.AreaFolder" = "Area"Datatypes are mapped and normalized to lowercase.
Units of measure are normalized through the UoM map.
from lxml import etree
from app.transformers.ampla_to_b2mml import AmplaTransformer
root = etree.parse("input.xml").getroot()
transformer = AmplaTransformer("config/mapping.toml")
model = transformer.transform(root)The model contains:
{
"equipment": [...],
"classes": [...],
"warnings": [...]
}b2mml convert input.xml output.xml
b2mml json input.xml
b2mml excel input.xml output.xlsx
b2mml csv equipment input.xml
b2mml csv classes input.xml
b2mml html input.xml report.html
b2mml diff baseline.xml updated.xml
Exit codes:
0→ no differences1→ differences found
b2mml validate input.xml
Exit codes:
0→ no warnings1→ warnings present
Start:
uvicorn app.api:app --reload
Endpoints:
| Method | Path | Description |
|---|---|---|
| POST | /convert/json |
JSON model |
| POST | /convert/xml |
B2MML XML |
| POST | /convert/excel |
Excel workbook |
| POST | /convert/csv/equipment |
Equipment CSV |
| POST | /convert/csv/classes |
Classes CSV |
| POST | /convert/html |
HTML report |
| POST | /stats |
Statistics |
| POST | /diff/json |
JSON diff |
| POST | /validate |
Validate model |
Start:
make up
Stop:
make down
Service runs at:
http://localhost:8000
app/parsers— XML parsingapp/transformers— Ampla → modelapp/builders— XML, JSON, Excel, CSV, HTMLapp/validators.py— structural checksapp/diff.py— diff engineapp/stats.py— statisticsapp/cli.py— CLIapp/api.py— FastAPI servicetests/— full regression suite
BSD 3‑Clause License.
This project includes B2MML V0600 XML Schema Definition files.
These files are copyrighted by MESA International and are provided under the MESA International License Agreement.