Exporting SCL Blocks as XML with TIA Portal Openness API
Structured Control Language (SCL) is Siemens' high-level, Pascal-derived text language for S7-1200, S7-1500, S7-300/400, and WinAC controllers programmed in the TIA Portal. Engineers building MES connectors, PLCOpen-style cross-vendor pipelines, or SCM-driven code-management workflows routinely need an XML representation of SCL code rather than the raw .scl source. TIA Portal V15 introduced a documented XML export/import interface for SCL blocks through the TIA Portal Openness API, and Siemens has continued to refine that schema in subsequent releases up to V20.
This reference consolidates the supported export paths, the documented XML element structure, the differences between the Siemens-specific Openness XML and the vendor-neutral PLCOpen XML schema, and the practical limitations you will hit when wiring an XML pipeline against an S7 program.
1. SCL Export Options at a Glance
| Format | Tool / Interface | Min. TIA Portal | Round-Trip Fidelity | Typical Use |
|---|---|---|---|---|
.scl (plain text) |
TIA Portal → Export → External Source | V13 | Full | Git/Subversion, diff/merge, hand editing |
.udt / .db (text) |
External Source compile/download | V13 | Full | UDT/DB versioning |
.xlsx (PLC tags) |
Project tree → Export Tags | V14 SP1 | Tag list only | Tag review, OPC tag mapping |
| XML (Openness) |
Siemens.Engineering.SW.Blocks.PlcBlock export |
V15 | Block-level, partial | MES, tool integration, automation pipelines |
| PLCOpen XML (TC6) | Third-party tooling (e.g., PLCopen Editor, CODESYS export) | N/A in TIA Portal | Not native | Cross-vendor code exchange, IEC 61131-10 conformance |
.scl source files and the Openness XML export preserve code body content. Tag XLSX export does not include any program logic. Any XML pipeline that needs to read or write statements in the SCL code body must go through TIA Portal Openness V15 or later.2. TIA Portal Openness API Prerequisites
The TIA Portal Openness API is a .NET-based automation interface that ships with the TIA Portal installation. It exposes the S7 program as a COM-visible object model.
- Install TIA Portal V15 (or later; current documentation targets V20). Openness is selected during installation under “TIA Portal Openness”.
- Add references to the Openness assemblies in your C# / VB.NET project:
Siemens.Engineering.dll-
Siemens.Engineering.Hmi.dll(HMI blocks) -
Siemens.Engineering.SW.dll(PLC software)
- Target .NET Framework 4.8 (V18+ supports .NET 6 / .NET 8 side-by-side assemblies; check the release notes for the exact TIA version in use).
- Run the host process as the same Windows user that opened TIA Portal, or launch TIA Portal in headless mode from the Openness application via
MyTiaPortal.StartWithoutGui()(V17+). - Disable “Automatic program save” prompts or handle the
TiaPortalModereturned byGetCurrentProcess()explicitly.
The official TIA Portal Openness API documentation is published at the Siemens documentation portal, including the V20 reference page for TIA Portal Openness. For SCL-specific block import/export see Export/Import of SCL call blocks.
3. Exporting an SCL Block to XML
The SCL body is exposed through the PlcBlock / PlcCodeBlock types. The XML serialisation is invoked through Export() on a block instance.
// C# / .NET 6 snippet - TIA Portal Openness V20
using Siemens.Engineering;
using Siemens.Engineering.SW;
using Siemens.Engineering.SW.Blocks;
TiaPortal tia = new TiaPortal(new TiaPortalProcessArguments());
Project project = tia.Projects.Open(new FileInfo(@"C:\Projects\Line01.ap18"));
foreach (Device device in project.Devices)
{
PlcSoftware plc = device.GetService<PlcSoftware>();
if (plc == null) continue;
foreach (PlcBlock block in plc.BlockGroup.Blocks)
{
if (block is PlcCodeBlock codeBlock && codeBlock.ProgrammingLanguage == ProgrammingLanguage.SCL)
{
FileInfo xmlFile = new FileInfo($"C:\\Export\\{codeBlock.Name}.xml");
codeBlock.Export(xmlFile, ExportOptions.WithDefaults);
Console.WriteLine($"Exported {codeBlock.Name} -> {xmlFile.FullName}");
}
}
}
Calling Export() with a .xml target extension triggers the Openness XML serializer. The resulting file is well-formed XML, namespace-qualified, and includes the block interface, the SCL statement body, and the SCL-specific metadata (compile time, author, version). The opposite path — Import() — accepts the same schema and recreates the block inside the project tree.
4. Documented XML Schema for SCL Blocks
The Openness XML is a Siemens-internal schema, not PLCOpen TC6. The V20 documentation describes the following key element types (refer to the official page for the full XSD):
| XML Element | Meaning | SCL Equivalent |
|---|---|---|
<Access> |
An operand or expression access | L-values, R-values, formal parameters |
<Constant> / <ConstantValue>
|
Literal constant |
42, 'Hello world', TRUE
|
<ConstantType> |
IEC 61131-3 type of the literal |
INT, STRING, BOOL
|
<Parameter> |
FB/FC call parameter (input, output, in-out) | MyFB(In := x, Out => y); |
<Informative> attribute |
Set when the parameter was not explicitly assigned in the field report | Default value placeholder |
<ReturnValue> |
Function return value | y := MyFC(); |
<StatementList> |
Sequence of SCL statements | Code body |
A literal string in SCL is serialised as shown below (this is the canonical example Siemens publishes):
#myString := 'Hello world'; // SCL source
<Access Scope="LocalVariable">
<Symbol>
<Component Name="myString" />
</Symbol>
<Access>
<Constant>
<ConstantValue>Hello world</ConstantValue>
<ConstantType Informative="true">STRING</ConstantType>
</Constant>
</Access>
</Access>
The Informative="true" flag on ConstantType tells the importer that the type was added by the serializer for round-trip safety, not declared explicitly in the original SCL. Round-trip tooling should strip or re-attribute such nodes before re-emitting SCL.
5. Round-Trip Behaviour: What XML Export Does Not Preserve
Openness XML export is sufficient for inspection, version control, and MES metadata exchange. It is not a lossless representation of the project. Documented limitations include:
-
Comments (
//and(* ... *)) are preserved as text nodes inside the statement list, but comment placement relative to statements may shift. -
Block attributes such as
{S7_optimized_DB_access := 'TRUE'}are exported but must be re-applied through thePlcBlockAttributecollection on import. - Multi-instance declarations inside FBs round-trip, but the instance DB name is regenerated by TIA Portal on import.
-
Know-how-protected blocks cannot be exported in XML. Openness throws
EngineeringTargetInvocationExceptionwith the inner exceptionSiemens.Engineering.EngineeringSecurityException. - Library-derived types (master copies from a global library) are referenced by symbolic name; the receiving project must have the same library version installed.
- Hardware identifiers (HW ID, channel names, slot numbers) belong to the device configuration, not the SCL block, and are not included.
.scl source files compiled in TIA Portal, or the DownloadToTarget API path.6. PLCOpen XML (IEC 61131-10) — The Vendor-Neutral Alternative
PLCOpen XML is the vendor-neutral exchange format defined by PLCopen Technical Committee 6 and adopted as IEC 61131-10. It is the format Beckhoff exports from TwinCAT through the Automation Interface, and it is the de-facto interchange format between CODESYS-based tools and third-party editors.
| Aspect | Siemens Openness XML | PLCOpen XML (IEC 61131-10) |
|---|---|---|
| Schema origin | Siemens-internal | PLCopen TC6 / IEC 61131-10 |
| Vendor support | Siemens only | Beckhoff, CODESYS, Schneider, ABB, B&R (varying) |
| Round-trip | Block-level | Project-level (POUs, GVLs, DUTs) |
| Body format | SCL statements, structured XML nodes | ST text inside <ST> / <body>
|
| Standardisation | None (Siemens proprietary) | IEC 61131-10:2019 / Amd 1:2024 |
| Tooling | Siemens Openness SDK only | PLCopen Editor, Beremiz, MATRIX, third-party SCM integrations |
TIA Portal does not natively import or export PLCOpen XML. Engineers targeting a vendor-neutral pipeline either (a) translate the Siemens Openness XML to PLCOpen XML through a custom XSLT or code generator, or (b) maintain a parallel SCL source tree that is checked in alongside the project and processed by a build server using Openness. Option (b) is the path Siemens’ own Continuous Integration demo for TIA Portal V18+ takes.
7. MES Integration via XML (Siemens UADM / UAPI)
Siemens MES offerings — notably the UADM (Unified Automation Data Management) and UAPI (Unified Automation Programming Interface) modules of Opcenter Execution / SIMATIC IT — use XML as their primary payload for recipe, tag, and code metadata exchange. The Openness XML export fits directly into a UADM “code sync” workflow:
- TIA Portal Openness exports the SCL block(s) as XML files into a watched folder.
- UADM ingests the XML, validates against its internal schema, and stores the block definition under a versioned artefact key.
- On a production release, UADM — or a downstream UAPI call — pushes the XML back into TIA Portal Openness, which imports it into the receiving project.
- Compile, download, and HMI tag generation run in the headless TIA Portal instance.
For brownfield projects where the SCL code already lives in a Siemens library, you can shortcut this by exporting .scl text files and wrapping them in a minimal XML envelope matching the UADM contract. This avoids invoking the full Openness V15 dependency on every CI run.
8. Version Control and XML — Field Reality
Git and Subversion merge tools handle line-based text well but produce noisy diffs on XML. Three patterns are used in production CI pipelines for TIA Portal projects:
| Pattern | Storage | Merge Tool | Pros | Cons |
|---|---|---|---|---|
A: Native .scl
|
ASCII | Git default | Clean diffs, no preprocessing | Requires TIA Portal to compile |
| B: Openness XML, pretty-printed | XML |
xmlstarlet + git merge=<driver>
|
Structured, queryable | Default Git merge is unusable without a driver |
C: .scl + .xml shadow |
Both | Mixed | Diff-friendly + MES-ready | Two files per block, must be kept in sync |
For pattern B, the recommended Git merge driver is a small XSLT that canonicalises the Openness XML (attribute order, namespace prefixes, whitespace) before storing the blob. The Siemens Continuous Integration (CI) sample on GitHub uses a similar approach with the tia-portal-openness Docker image for V18+.
9. Supported Versions and Known Issues
| TIA Portal | Openness XML Status | Notes |
|---|---|---|
| V13 SP1 | Not available | Openness exists; no SCL XML export |
| V14 / V14 SP1 | Not available | External source export only |
| V15 / V15.1 | Introduced | First SCL XML export, basic round-trip |
| V16 | Extended | Added multi-instance support |
| V17 | Extended | Headless TIA Portal mode introduced |
| V18 | Extended | Library master copies round-trip reliably |
| V19 | Extended | Performance improvements on bulk export |
| V20 | Current | Documented Informative attribute on ConstantType; better SCL call parameter handling |
Common error codes returned during XML export/import via Openness:
| Exception | Cause | Remediation |
|---|---|---|
EngineeringTargetInvocationException |
Block is know-how protected or in a locked library | Remove protection; reference the master copy |
EngineeringNotSupportedException |
Calling XML export on a non-SCL block | Filter by ProgrammingLanguage.SCL
|
EngineeringXmlSchemaValidationException |
Import XML is malformed or uses an older schema | Re-export from the matching TIA Portal version |
EngineeringRuntimeException with inner UnauthorizedAccessException
|
Target directory is read-only or locked by another process | Use a per-job export directory |
10. Verification Checklist
After an XML export/import cycle, validate with the following checks:
- Open the receiving project in TIA Portal; verify the block appears in the project tree with the same name and number.
- Open the block in the SCL editor; confirm the code body compiles without errors (Compile → Software (rebuild all)).
- Diff the XML
<StatementList>element against the source — only theInformative="true"nodes should differ on a clean round trip. - Compare the block interface (inputs, outputs, in-outs, stat, temp) against the source block using Project tree → Properties → Interface.
- Run the project through the TIA Portal Check consistency command to catch any cross-block reference breaks (UDTs, FB multi-instances, GVLs).
- If the block is part of a program download, trigger a Download to device simulation to confirm the compiled block is accepted by the S7-PLCSIM instance.
11. Practical Recommendations
-
Default to
.sclfor SCM. Use plain SCL text for day-to-day version control. Reserve the Openness XML for tool integration, MES sync, and ad-hoc inspection. - Lock the Openness version. The XML schema evolves. Pin a specific TIA Portal version (e.g., V20) on every CI job and reject cross-version XML diffs to keep the build green.
-
Validate before import. Run the XML through
xmllint --schema tia-openness.xsdwith the official XSD (V20 schema is shipped with the Openness installer underSiemens\Automation\Portal V20\Openness\Schemas) before pushing it back into TIA Portal. - Don't reinvent PLCOpen. If the goal is vendor-neutral exchange, generate PLCOpen XML from the Openness XML using an XSLT rather than maintaining two parallel code-bases.
-
Watch know-how protection. Add a pre-export check that skips any block with
BlockProtection.PlcBlockProtectionAttributeset, and log the skip with the block path so audit trails stay complete. -
Mind the WinCC / HMI coupling. If the SCL block is referenced from an HMI tag list, re-export the
.xlsxtag table after the import to keep the HMI in sync.
12. Reference Summary
| Item | Value |
|---|---|
| First TIA version with SCL XML export | V15 (2017) |
| Current documented version | V20 |
| API namespace | Siemens.Engineering.SW.Blocks |
| Export call | PlcCodeBlock.Export(FileInfo, ExportOptions) |
| Import call | PlcBlockGroup.Blocks.Import(FileInfo, ImportOptions) |
| Schema namespace | http://www.siemens.com/automation/Openness/PLC/Blocks |
| External standard equivalent | IEC 61131-10 (PLCOpen XML TC6) |
| Runtime requirement | .NET Framework 4.8 (V18+ also .NET 6/8) |
| License | TIA Portal Openness license, included with STEP 7 Professional |
Can TIA Portal V13 SP1 export SCL blocks as XML?
No. The SCL XML export/import interface was introduced in TIA Portal V15 (2017). V13 SP1 supports Openness automation, but only for non-SCL block operations and only through the legacy S7 API path. To export SCL as XML you must upgrade the engineering station to V15 or later; V20 is the current documented release.
Does the Openness XML export preserve SCL comments and formatting?
Comments are stored as text nodes inside the <StatementList> element and survive the round trip, but exact character position, indentation, and trailing whitespace are not preserved. The serializer normalises whitespace on export. If diff-friendly source is required, use the .scl external source file export and check that into version control instead.
What is the difference between Siemens Openness XML and PLCOpen XML?
Siemens Openness XML is a proprietary schema designed for round-trip with TIA Portal and integration with Siemens MES modules (UADM, UAPI). PLCOpen XML (IEC 61131-10) is the vendor-neutral exchange format supported by Beckhoff, CODESYS, Schneider, and others. TIA Portal does not natively read or write PLCOpen XML. Choose Openness XML for MES and CI workflows inside a Siemens-only environment; choose PLCOpen XML when exchanging POUs with third-party IEC 61131-3 tools.
How do I export only the SCL blocks from a project, not the FBD or LAD blocks?
Filter the PlcBlockGroup.Blocks collection by ProgrammingLanguage.SCL before calling Export(). Use the PlcCodeBlock derived type and check codeBlock.ProgrammingLanguage == ProgrammingLanguage.SCL. Exporting an FBD or LAD block to XML through the same code path raises an EngineeringNotSupportedException.
Can I version-control Openness XML files directly in Git?
Yes, but only with a custom merge driver. The default Git text merge produces unusable diffs on multi-line attribute changes. Use a canonicalising XSLT (attribute sort, namespace prefix standardisation, indentation) to preprocess the XML before storing the blob, and configure .gitattributes with *.xml merge=openness pointing to a driver script. For most projects the simpler choice is to version-control the .scl source and generate the XML on demand in CI.
Why does XML export fail with an EngineeringSecurityException?
Know-how-protected blocks (those assigned a PlcBlockProtectionAttribute with KnowHowProtection or CopyProtection) cannot be serialised. The Openness API throws EngineeringTargetInvocationException wrapping EngineeringSecurityException. Remove the protection attribute in TIA Portal before running the export, or skip the block in your toolchain and log the skip with the block path for audit purposes.