Skip to main content

redispatch_xml/
lib.rs

1//! `redispatch-xml` — Redispatch 2.0 XML/XSD format parsing and validation
2//! for the German electricity grid (§§ 13, 13a, 14 EnWG).
3//!
4//! # Domain background
5//!
6//! **Redispatch 2.0** entered into force on **1 October 2021** via the
7//! Netzausbaubeschleunigungsgesetz (NABEG) and requires all German grid
8//! operators to coordinate congestion management across transmission and
9//! distribution networks. It covers:
10//!
11//! - All renewable-energy (EE) and combined heat-and-power (KWK) plants
12//!   with ≥ 100 kW installed capacity
13//! - All installations permanently remote-controllable by a grid operator
14//!   (e.g. via Smart-Meter-Gateway)
15//!
16//! # Format family
17//!
18//! Redispatch 2.0 uses CIM/IEC 62325-based XML documents for the primary data
19//! exchange between TSOs, DSOs, and balance responsible parties. Documents are
20//! validated against BDEW-published XSD schemas (topicGroupId 25 in the BDEW
21//! MaKo document API).
22//!
23//! | Document type | XSD version | Latest revision |
24//! |---|---|---|
25//! | `ActivationDocument` | 1.1f | Fehlerkorrektur 2026-02-19 |
26//! | `PlannedResourceScheduleDocument` | 1.0f | Fehlerkorrektur 2026-02-19 |
27//! | `AcknowledgementDocument` | 1.0g | 2025-10-01 |
28//! | `Stammdaten` | 1.4b | Fehlerkorrektur 2026-02-19 |
29//! | `StatusRequest_MarketDocument` | 1.1 | 2025-04-01 |
30//! | `Unavailability_MarketDocument` | 1.1b | Fehlerkorrektur 2025-04-16 |
31//! | `Kaskade` | 1.0 | Fehlerkorrektur 2026-02-19 |
32//! | `NetworkConstraintDocument` | 1.1b | 2025-04-01 |
33//! | `Kostenblatt` | 1.0d | Fehlerkorrektur 2025-04-16 |
34//!
35//! These are **not** EDIFACT. IFTSTA status messages for the Redispatch 2.0
36//! workflow are handled separately by the `edi-energy` crate.
37//!
38//! ## Validation is structural and semantic, never XSD
39//!
40//! This crate ships **no** schema bytes and performs **no** XSD validation.
41//! The BDEW XSDs are third-party copyrighted publications and are not
42//! redistributable, so embedding them here would put someone else's material in
43//! every copy of this crate and make a clean build depend on a file that is not
44//! part of it. A `bundled-schemas` Cargo feature once promised a
45//! `schema_bytes(DocumentType)` accessor for exactly that; it was declared
46//! empty, exported nothing, and has been removed — a feature flag that does
47//! nothing reads as a supported configuration.
48//!
49//! What replaces it is [`validation`]: the structural checks assert the
50//! cardinalities and required elements the XSDs express, and the semantic
51//! checks assert the rules the XSDs *cannot* express. Callers who must validate
52//! against the published schema do so with their own copy and their own XSD
53//! processor.
54//!
55//! # Market roles
56//!
57//! | Role | Abbrev. | Description |
58//! |------|---------|-------------|
59//! | Übertragungsnetzbetreiber | ÜNB | Transmission system operator |
60//! | Verteilnetzbetreiber | VNB | Distribution system operator |
61//! | Anlagenbetreiber | ANB | Generation asset operator |
62//! | Direktvermarkter | DV | Direct marketer of renewable energy |
63//! | Bilanzkreisverantwortlicher | BKV | Balance responsible party |
64//!
65//! # Quick start
66//!
67//! ```rust,no_run
68//! use redispatch_xml::{parse, Document};
69//!
70//! let xml: &[u8] = b"<ActivationDocument xmlns=\"urn:entsoe.eu:wgedi:errp:activationdocument:5:0\">...</ActivationDocument>";
71//! match parse(xml) {
72//!     Ok(Document::Activation(doc)) => println!("Got ACO/ACR/AAR: {:?}", doc.document_type),
73//!     Ok(other) => println!("Other document type: {:?}", other.document_type()),
74//!     Err(e) => eprintln!("Parse error: {e}"),
75//! }
76//! ```
77//!
78//! # Regulatory references
79//!
80//! - **§§ 13, 13a, 14 EnWG** — statutory basis for grid congestion management
81//! - **NABEG 2019** — introduced Redispatch 2.0, effective 1 October 2021
82//! - **BNetzA BK6-20-059/060/061** — three BNetzA rulings governing billing
83//!   balance, grid operator coordination, and information provision
84//! - **BDEW XML-Datenformate Redispatch 2.0** — XSD schemas and application
85//!   guidelines published on [bdew-mako.de](https://www.bdew-mako.de)
86
87#![deny(unsafe_code)]
88#![deny(missing_docs)]
89
90pub mod documents;
91pub mod error;
92mod parse;
93mod serialize;
94pub mod types;
95pub mod validation;
96
97// ── Top-level re-exports ──────────────────────────────────────────────────────
98
99pub use documents::{
100    AcknowledgementDocument, ActivationDocument, DocumentType, Kaskade, Kostenblatt,
101    NetworkConstraintDocument, PlannedResourceScheduleDocument, Stammdaten,
102    StatusRequestMarketDocument, UnavailabilityMarketDocument,
103};
104pub use error::RedispatchXmlError;
105pub use parse::{Document, detect, parse, parse_and_validate, parse_as};
106pub use serialize::{serialize, serialize_as};
107pub use validation::{ValidationResult, ValidationWarning, validate};