Skip to content
A

BROParser

Defined in: src/parser.ts:75

Main BRO Parser class

Usage:

import { BROParser, XMLAdapter } from '@bedrock-engineer/bro-xml-parser';
const parser = new BROParser(new XMLAdapter());
const cptData = parser.parseCPT(xmlString);
// Check for warnings
if (cptData.meta.warnings.length > 0) {
console.warn('Parse warnings:', cptData.meta.warnings);
}
new BROParser(adapter, namespaces?): BROParser;

Defined in: src/parser.ts:85

Create a BRO parser instance

ParameterTypeDescription
adapterXMLAdapterXML adapter for the target environment (browser/Node.js)
namespaces?NamespacesOptional namespace overrides (defaults to BRO_NAMESPACES)

BROParser

parseCPT(xmlText): CPTData;

Defined in: src/parser.ts:151

Parse CPT data from BRO/XML string

Extracts all 41 metadata fields and measurement data following the IMBRO CPT schema (dscpt/1.1).

ParameterTypeDescription
xmlTextstringBRO/XML document as string

CPTData

Parsed CPT data with metadata and measurements

If parsing fails or required fields are missing

const parser = new BROParser(new XMLAdapter());
const cptData = parser.parseCPT(xmlString);
console.log(cptData.broId); // "CPT000000155283"
console.log(cptData.finalDepth); // 10.5
console.log(cptData.data.length); // 525 measurements
console.log(cptData.data[0].coneResistance); // 1.234
console.log(cptData.meta.schemaVersion); // "1.1"

parseBHRGT(xmlText): BHRGTData;

Defined in: src/parser.ts:177

Parse Bore (borehole) data from BRO/XML string

Extracts metadata and layer information following the IMBRO Bore schema (dsbhr-gt/2.1).

ParameterTypeDescription
xmlTextstringBRO/XML document as string

BHRGTData

Parsed BHR-GT data with metadata and soil layers

If parsing fails or required fields are missing

const parser = new BROParser(new XMLAdapter());
const BHRGTData = parser.parseBHRGT(xmlString);
console.log(BHRGTData.broId); // "BHR000000123456"
console.log(BHRGTData.finalBoreDepth); // 5.5
console.log(BHRGTData.data.length); // 8 layers
console.log(BHRGTData.data[0].geotechnicalSoilName); // "zand"
console.log(BHRGTData.meta.schemaVersion); // "2.1"

parseBHRG(xmlText): BHRGData;

Defined in: src/parser.ts:203

Parse BHR-G (Geological Borehole) data from BRO/XML string

Extracts metadata and layer information following the IMBRO BHR-G schema (dsbhrg/3.1).

ParameterTypeDescription
xmlTextstringBRO/XML document as string

BHRGData

Parsed BHR-G data with metadata and soil layers

If parsing fails or required fields are missing

const parser = new BROParser(new XMLAdapter());
const BHRGData = parser.parseBHRG(xmlString);
console.log(BHRGData.broId); // "BHR000000123456"
console.log(BHRGData.finalBoreDepth); // 3.0
console.log(BHRGData.data.length); // 5 layers
console.log(BHRGData.data[0].soilNameNEN5104); // "zwakZandigeKlei"
console.log(BHRGData.meta.schemaVersion); // "3.1"

parseGMW(xmlText): GMWData;

Defined in: src/parser.ts:229

Parse GMW (groundwater monitoring well) data from BRO/XML string

Extracts well metadata and its monitoring tubes following the IMBRO GMW schema (dsgmw/1.1). Works on the public dispatch document (GMW_PPO) as well as the GMW_PO / GMW_O variants, which share one leaf surface.

ParameterTypeDescription
xmlTextstringBRO/XML document as string

GMWData

Parsed GMW data with metadata and monitoring tubes

If parsing fails or required fields are missing

const parser = new BROParser(new XMLAdapter());
const gmw = parser.parseGMW(xmlString);
console.log(gmw.broId); // "GMW000000048066"
console.log(gmw.numberOfMonitoringTubes); // 1
console.log(gmw.monitoringTube[0].screen?.screenLength); // 1.0
console.log(gmw.meta.schemaVersion); // "1.1"

parseGLD(xmlText): GLDData;

Defined in: src/parser.ts:258

Parse GLD (groundwater level research) data from BRO/XML string

Extracts the monitoring-point reference, monitoring-net membership and the groundwater level observation time-series following the IMBRO GLD schema (dsgld/1.0).

Note: full GLD dispatch documents can be very large (years of time-series measurements). Consider requesting a bounded observation period from the BRO REST API before parsing.

ParameterTypeDescription
xmlTextstringBRO/XML document as string

GLDData

Parsed GLD data with metadata and observation series

If parsing fails or required fields are missing

const parser = new BROParser(new XMLAdapter());
const gld = parser.parseGLD(xmlString);
console.log(gld.broId); // "GLD000000010000"
console.log(gld.monitoringPoint?.broId); // "GMW000000020142"
console.log(gld.observation[0].points.length); // 8760

parse(xmlText): BROData;

Defined in: src/parser.ts:290

Parse any BRO XML document, auto-detecting the data type

This is the recommended entry point when you don’t know the file type in advance. The method detects the data type from the XML namespace and calls the appropriate parser.

ParameterTypeDescription
xmlTextstringBRO/XML document as string

BROData

Parsed data (CPTData, BHRGTData, or BHRGData)

If parsing fails or data type is unknown

const parser = new BROParser(new XMLAdapter());
const data = parser.parse(xmlString);
// Discriminate on the top-level dataType (narrows the union)
switch (data.dataType) {
case 'CPT':
console.log(data.finalDepth);
break;
case 'BHR-GT':
case 'BHR-G':
console.log(data.finalBoreDepth);
break;
}

parseCustom<F>(
xmlText,
fields,
dataType?
): { [K in string | number | symbol]: ({ [K in string | number | symbol]: FieldValue<F[K]> } & { [K in string | number | symbol]?: FieldValue<F[K]> })[K] } & object;

Defined in: src/parser.ts:337

Parse BRO XML with a custom schema for selective extraction

This allows you to extract only the fields you need, which can be more efficient and gives you full control over the output structure.

Pass a bare map of field name → Producer, built from the producers authoring surface. The return type is inferred from the map: each field’s type is its producer’s output type, plus a meta block. Author the map as an inline literal (or with satisfies Record<string, Producer<unknown>>) so the field types are preserved for inference.

Type Parameter
F extends Record<string, Producer<unknown, Presence>>
ParameterTypeDescription
xmlTextstringBRO/XML document as string
fieldsFField name → producer map defining what to extract
dataType?BROFileTypeThe BRO data type (for version validation)

{ [K in string | number | symbol]: ({ [K in string | number | symbol]: FieldValue<F[K]> } & { [K in string | number | symbol]?: FieldValue<F[K]> })[K] } & object

Object with extracted fields matching your map, plus meta

import { BROParser, producers as p } from '@bedrock-engineer/bro-xml-parser';
const parser = new BROParser(new XMLAdapter());
// Define only the fields you need
const result = parser.parseCustom(xmlText, {
id: p.text('brocom:broId'), // string | null
depth: p.number('./dscpt:conePenetrometerSurvey/cptcommon:trajectory/cptcommon:finalDepth'),
location: p.gmlLocation('./dscpt:deliveredLocation/cptcommon:location'),
}, 'CPT');
result.depth; // number | null — inferred, no casts
result.location; // Location | null

parseSelection<T>(
xmlText,
selection,
dataType?
): T & object;

Defined in: src/parser.ts:368

Parse BRO XML with a project() selection — a selector over the full producer schema (CPT_PRODUCER, …). The result is the projected shape plus meta, with no hand-written XPaths.

Type Parameter
T
ParameterType
xmlTextstring
selectionObjectProducer<T>
dataType?BROFileType

T & object

import { project, CPT_PRODUCER } from '@bedrock-engineer/bro-xml-parser/node';
const survey = project(CPT_PRODUCER, (t) => ({
id: t.broId,
depth: t.finalDepth,
klass: t.qualityClass, // Coded | null
}));
const r = parser.parseSelection(xml, survey, 'CPT'); // { id, depth, klass, meta }

getAdapter(): XMLAdapter;

Defined in: src/parser.ts:403

Get the underlying XML adapter (useful for advanced use cases or testing)

XMLAdapter