GAEB DA XML Engine
Relevant source files
The following files were used as context for generating this wiki page:
- lib/gaeb/parser.ts
- lib/gaeb/export.ts
- lib/gaeb/text-parser.test.ts
- lib/gaeb/parser.test.ts
- app/(chat)/lv/import-actions.ts/lv/import-actions.ts)
- app/(chat)/lv/[projectId]/export/route.ts/lv/[projectId]/export/route.ts)
The GAEB DA XML Engine processes GAEB (Gemeinsamer Ausschuss Elektronik im Bauwesen) data exchange formats for construction service specifications. It parses, validates, and exports XML files following the GAEB DA XML 3.2 and 3.3 specifications, which are the standard for data exchange in Germany, Austria, and Switzerland (D/A/CH). Sources: lib/gaeb/parser.ts:4-6, lib/gaeb/export.ts:1-10.
The engine handles various exchange phases, known as "X-formats" (e.g., X81 for service descriptions, X83 for requests for quotations), ensuring interoperability between LV.AI and external architectural or construction software. Sources: lib/gaeb/parser.ts:8-17, CLAUDE.md:12-18.
Architecture and Data Flow
The engine consists of two primary modules: the GaebParser for ingesting XML data and the GaebExport module for generating compliant files. The system interacts with the PostgreSQL database via Drizzle ORM to persist imported Bill of Quantities (BoQ) positions or retrieve them for export. Sources: lib/gaeb/parser.ts:31, lib/gaeb/export.ts:34, app/(chat)/lv/import-actions.ts:121-155.
Integration Flow
The following diagram illustrates how a GAEB file moves through the system from an initial user upload to database persistence and subsequent export.
GAEB Parsing Logic
The GaebParser class extracts project metadata and BoQ items from XML strings using regular expressions. This approach allows the engine to function in environments where a full DOM parser might be unavailable. Sources: lib/gaeb/parser.ts:31-72.
Key Parsing Methods
detectFormat(xml): Identifies the GAEB exchange phase (e.g., X83) by matching the XML namespace string. Sources: lib/gaeb/parser.ts:34-41.parse(xml): The main entry point that validates the presence of the<GAEB>root element and extracts project names and positions. Sources: lib/gaeb/parser.ts:46-86.extractPositionsFromXml(xml): Iterates through<Item>elements to capture ordinal numbers (OZ), short texts, long texts, quantities, and units. Sources: lib/gaeb/parser.ts:106-136.
Supported GAEB Phases
| Format | Description | German Term |
|---|---|---|
| X81 | Service Description | Leistungsbeschreibung |
| X82 | Cost Estimate | Kostenanschlag |
| X83 | Request for Quotation | Angebotsaufforderung |
| X84 | Bid Submission | Angebotsabgabe |
| X86 | Award of Contract | Auftragserteilung |
| X89 | Invoice | Rechnung |
Sources: lib/gaeb/parser.ts:8-17, lib/gaeb/export.ts:18
GAEB Export Engine
The export module generates valid GAEB DA XML 3.3 files. It maps internal database structures back to the hierarchical GAEB schema, including Award, Lot, and BoQ blocks. Sources: lib/gaeb/export.ts:34-63.
Logic and Constraints
The exportGaebXml function performs strict validation before generation. It requires a project name and at least one BoQ position with an ordinal number (OZ) and short description. Sources: lib/gaeb/export.ts:182-218.
The engine also implements localized currency mapping based on the project's region:
- DE (Germany): EUR
- AT (Austria): EUR
- CH (Switzerland): CHF
Sources: lib/gaeb/export.ts:41-45
Export Sequence
The sequence below details how the system handles an export request through the API route.
Data Structures
The engine uses standardized interfaces to represent GAEB entities across the parser and export modules. Sources: lib/gaeb/parser.ts:19-30.
GaebPosition Interface
| Field | Type | Description |
|---|---|---|
oz | string | Ordinal number (Ordnungszahl), e.g., "01.0020" |
kurztext | string | Short description |
langtext | string (optional) | Full detailed description |
menge | string (optional) | Quantity |
einheit | string (optional) | Unit of measurement (e.g., m3, Stk) |
einheitspreis | string (optional) | Unit price (EP) |
gesamtpreis | string (optional) | Total price (GP) |
Sources: lib/gaeb/parser.ts:19-28
Implementation Details
Normalization during Import
When importing positions, the system normalizes ordinal numbers (OZ) by replacing multiple consecutive dots with a single dot (e.g., 5..40 becomes 5.40) to ensure internal consistency. Sources: app/(chat)/lv/import-actions.ts:128.
XML Escaping
Both parsing and exporting utilities include specialized logic to handle XML-sensitive characters (&, <, >, ", ') to prevent malformed XML generation or injection. Sources: lib/gaeb/parser.ts:175-182, lib/gaeb/export.ts:221-230.
// From lib/gaeb/parser.ts:175-182
private escapeXml(text: string): string {
return text
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
Summary
The GAEB DA XML Engine provides the critical interoperability layer for LV.AI. By supporting the DA 3.2 and 3.3 standards, it enables seamless transitions between chat-based AI generation and formal construction industry documentation requirements in the D/A/CH region. Sources: lib/gaeb/parser.ts:4-6, CLAUDE.md:12-18.