BROParser
Class: BROParser
Section titled “Class: BROParser”Defined in: src/parser.ts:48
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 warningsif (cptData.meta.warnings.length > 0) { console.warn('Parse warnings:', cptData.meta.warnings);}Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BROParser(adapter, namespaces?): BROParser;Defined in: src/parser.ts:58
Create a BRO parser instance
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
adapter | XMLAdapter | XML adapter for the target environment (browser/Node.js) |
namespaces? | Namespaces | Optional namespace overrides (defaults to BRO_NAMESPACES) |
Returns
Section titled “Returns”BROParser
Methods
Section titled “Methods”parseCPT()
Section titled “parseCPT()”parseCPT(xmlText): CPTData;Defined in: src/parser.ts:102
Parse CPT data from BRO/XML string
Extracts all 41 metadata fields and measurement data following the IMBRO CPT schema (dscpt/1.1).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
xmlText | string | BRO/XML document as string |
Returns
Section titled “Returns”Parsed CPT data with metadata and measurements
Throws
Section titled “Throws”If parsing fails or required fields are missing
Example
Section titled “Example”const parser = new BROParser(new XMLAdapter());const cptData = parser.parseCPT(xmlString);
console.log(cptData.broId); // "CPT000000155283"console.log(cptData.finalDepth); // 10.5console.log(cptData.data.length); // 525 measurementsconsole.log(cptData.data[0].coneResistance); // 1.234console.log(cptData.meta.schemaVersion); // "1.1"parseBHRGT()
Section titled “parseBHRGT()”parseBHRGT(xmlText): BHRGTData;Defined in: src/parser.ts:135
Parse Bore (borehole) data from BRO/XML string
Extracts metadata and layer information following the IMBRO Bore schema (dsbhr-gt/2.1).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
xmlText | string | BRO/XML document as string |
Returns
Section titled “Returns”Parsed BHR-GT data with metadata and soil layers
Throws
Section titled “Throws”If parsing fails or required fields are missing
Example
Section titled “Example”const parser = new BROParser(new XMLAdapter());const BHRGTData = parser.parseBHRGT(xmlString);
console.log(BHRGTData.broId); // "BHR000000123456"console.log(BHRGTData.finalBoreDepth); // 5.5console.log(BHRGTData.data.length); // 8 layersconsole.log(BHRGTData.data[0].geotechnicalSoilName); // "zand"console.log(BHRGTData.meta.schemaVersion); // "2.1"parseBHRG()
Section titled “parseBHRG()”parseBHRG(xmlText): BHRGData;Defined in: src/parser.ts:168
Parse BHR-G (Geological Borehole) data from BRO/XML string
Extracts metadata and layer information following the IMBRO BHR-G schema (dsbhrg/3.1).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
xmlText | string | BRO/XML document as string |
Returns
Section titled “Returns”Parsed BHR-G data with metadata and soil layers
Throws
Section titled “Throws”If parsing fails or required fields are missing
Example
Section titled “Example”const parser = new BROParser(new XMLAdapter());const BHRGData = parser.parseBHRG(xmlString);
console.log(BHRGData.broId); // "BHR000000123456"console.log(BHRGData.finalBoreDepth); // 3.0console.log(BHRGData.data.length); // 5 layersconsole.log(BHRGData.data[0].soilNameNEN5104); // "zwakZandigeKlei"console.log(BHRGData.meta.schemaVersion); // "3.1"parse()
Section titled “parse()”parse(xmlText): BROData;Defined in: src/parser.ts:207
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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
xmlText | string | BRO/XML document as string |
Returns
Section titled “Returns”Parsed data (CPTData, BHRGTData, or BHRGData)
Throws
Section titled “Throws”If parsing fails or data type is unknown
Example
Section titled “Example”const parser = new BROParser(new XMLAdapter());const data = parser.parse(xmlString);
// Use meta.dataType to discriminateswitch (data.meta.dataType) { case 'CPT': console.log(data.finalDepth); break; case 'BHR-GT': case 'BHR-G': console.log(data.finalBoreDepth); break;}parseCustom()
Section titled “parseCustom()”parseCustom( xmlText, schema, dataType?): Record<string, unknown> & object;Defined in: src/parser.ts:261
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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
xmlText | string | BRO/XML document as string |
schema | Schema | Custom schema defining fields to extract |
dataType? | BROFileType | The BRO data type (for version validation) |
Returns
Section titled “Returns”Record<string, unknown> & object
Object with extracted fields matching your schema
Example
Section titled “Example”import { BROParser, resolvers } from '@bedrock-engineer/bro-xml-parser';
const parser = new BROParser(new XMLAdapter());
// Define only the fields you needconst mySchema = { id: { xpath: 'brocom:broId' }, depth: { xpath: './/cptcommon:finalDepth', resolver: resolvers.parseFloat }, location: { xpath: './dscpt:deliveredLocation/cptcommon:location', resolver: resolvers.parseGMLLocation }};
const result = parser.parseCustom(xmlText, mySchema, 'CPT');// { id: "CPT000000099543", depth: 25.5, location: { x: 155000, y: 463000, epsg: "EPSG:28992" } }getAdapter()
Section titled “getAdapter()”getAdapter(): XMLAdapter;Defined in: src/parser.ts:298
Get the underlying XML adapter (useful for advanced use cases or testing)
Returns
Section titled “Returns”XMLAdapter