Tolerant in
Namespaces under http://levelC/…, a payload without xsi:type, required elements left out, a decimal comma in a number: the reader accepts the deviations national feeds really have, and reads the rest of the document.
DATEX II v3 · XML and JSON · read · stream · write
datex2 reads, streams and writes DATEX II, the European standard for road traffic and travel information. One call turns a national feed, XML or JSON, into typed data. The reader tolerates what real feeds send and tells you what it tolerated; the writer produces only documents the official schemas accept, including AFIR charging data for Germany's Mobilithek.
cargo add datex2use datex2::v3::{self, Publication};
use std::{fs::File, io::BufReader};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = BufReader::new(File::open("incidents.xml")?);
let doc = v3::read(file)?;
for publication in &doc.publications {
if let Publication::Situation(p) = publication {
println!("{} situations", p.situation.len());
}
}
for warning in &doc.warnings {
eprintln!("{warning}"); // what was tolerated, and where
}
Ok(())
}Road operators, access points and charging operators across Europe publish DATEX II. The standard is large and real feeds bend it. These rules are what makes the data usable anyway.
Namespaces under http://levelC/…, a payload without xsi:type, required elements left out, a decimal comma in a number: the reader accepts the deviations national feeds really have, and reads the rest of the document.
Every deviation is a warning with its kind, the element path and the byte offset. Unknown elements are reported, extension content is kept as it was written, and no value is ever made up.
The writer checks required content, list sizes and every value rule of the schema. When it succeeds, the official 3.7 schemas, or the Mobilithek profile's, accept the document; when it cannot, it names the place, the rule and the schema type. It never rounds.
Nesting, attributes and token length are bounded while reading, document type declarations are refused, every text in an error is made safe to log, and the reader is fuzzed. There is no unsafe.
You do not state a version, a namespace, a schema or an envelope. The crate works on the bytes you give it and opens no files or sockets of its own.
payload, a messageContainer with several payloads, a root named after the publication, and SOAP around any of them.SituationRecord is SituationRecord, so the official documentation applies to the Rust types.record.validity() works for an accident, roadworks and every other kind of situation record.| You want to | Call |
|---|---|
| Read a document | v3::read(input) |
| Process a large feed record by record | v3::stream::<T>(input) |
| Publish a publication or a message container | v3::write(sink, &publication), v3::write(sink, &container) |
| Read or write JSON | v3::json::read(input), v3::json::write(…) |
| Publish charging data for the Mobilithek | mobilithek::write(sink, &table), mobilithek::snapshot(status, at) |
| See what a file contains | cargo run --example inspect |
Every publication of DATEX II 3.7, in XML and JSON.
| Area | State |
|---|---|
| Situations (EN 16157-3) | Accidents, roadworks, closures, speed management and every other situation record |
| Traffic data (EN 16157-5) | Measured data, elaborated data, measurement site tables |
| Variable message signs (EN 16157-4) | VMS publications and tables |
| Parking (CEN/TS 16157-6) | Parking tables and status |
| Energy infrastructure (CEN/TS 16157-10) | Charging and refuelling points: the 2022 namespaces and the AFIR namespaces of 3.7 |
| Traffic regulations and controlled zones (CEN/TS 16157-11) | Regulation orders, low-emission and access zones |
| Traffic management, facilities, devices and faults | Traffic management plans, rerouting, facilities and rates, device and fault publications |
| Location referencing (EN 16157-2) | Coordinates, linear and area locations, Alert-C, TPEG-Loc and OpenLR data, as typed values |
| JSON | The official 3.7 mapping, and the AFIR Recharging profile the Mobilithek requires, read and written with exact numbers |
| Reading, streaming, writing | Whole documents, one record at a time in bounded memory, and schema-valid output |
Named, so that you do not have to find out.
This release handles version 3. The version 2 model, which several countries still publish, is not read yet.
No HTTP client, no SOAP services, no Exchange 2020 protocol. A messageContainer yields its payloads and its exchange information, such as snapshot or delta, and nothing more.
Parking, controlled-zone and traffic-regulation documents written against releases before 3.6 lose the elements that 3.7 renamed; each is reported.