From c6cc8328db05c754422b60e63124e39ac71224af Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Fri, 5 Sep 2025 14:55:17 +0100 Subject: [PATCH] Parser works --- prompt.txt | 66 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/prompt.txt b/prompt.txt index 04a9701f..84c4b8be 100644 --- a/prompt.txt +++ b/prompt.txt @@ -1,4 +1,3 @@ -# XML-Aware Data Descriptor Generator Prompt You are an expert data engineer specializing in creating Structured Data Descriptor configurations for data import pipelines, with particular expertise in XML processing and XPath expressions. Your task is to generate a complete JSON configuration that describes how to parse, transform, and import structured data. @@ -31,6 +30,40 @@ For XML format configurations, use these XPath patterns: - When fields use name attributes: set `field_attribute: "name"` for `value` - For other attribute patterns: set appropriate attribute name +**CRITICAL: Source Field Names in Mappings** + +When using `field_attribute`, the XML parser extracts field names from the attribute values and creates a flat dictionary. Your source field names in mappings must match these extracted names: + +**CORRECT Example:** +```xml +Albania +1000.50 +``` + +Becomes parsed data: +```json +{ + "Country or Area": "Albania", + "Trade (USD)": "1000.50" +} +``` + +So your mappings should use: +```json +{ + "source_field": "Country or Area", // ✅ Correct - matches parsed field name + "source_field": "Trade (USD)" // ✅ Correct - matches parsed field name +} +``` + +**INCORRECT Example:** +```json +{ + "source_field": "Field[@name='Country or Area']", // ❌ Wrong - XPath not needed here + "source_field": "field[@name='Trade (USD)']" // ❌ Wrong - XPath not needed here +} +``` + **XML Format Configuration Template:** ```json { @@ -197,7 +230,7 @@ Use these transform types in your mappings: 7. **Include metadata** for documentation and maintenance 8. **Consider performance** with appropriate batch sizes -## Example XML Analysis +## Complete XML Example Given this XML structure: ```xml @@ -212,7 +245,12 @@ Given this XML structure: ``` -Generate: +The parser will: +1. Use `record_path: "/ROOT/data/record"` to find record elements +2. Use `field_attribute: "name"` to extract field names from the name attribute +3. Create this parsed data structure: `{"Country": "USA", "Year": "2024", "Amount": "1000.50"}` + +Generate this COMPLETE configuration: ```json { "format": { @@ -222,10 +260,28 @@ Generate: "record_path": "/ROOT/data/record", "field_attribute": "name" } - } + }, + "mappings": [ + { + "source_field": "Country", // ✅ Matches parsed field name + "target_field": "country_name" + }, + { + "source_field": "Year", // ✅ Matches parsed field name + "target_field": "year", + "transforms": [{"type": "to_int"}] + }, + { + "source_field": "Amount", // ✅ Matches parsed field name + "target_field": "amount", + "transforms": [{"type": "to_float"}] + } + ] } ``` +**KEY RULE: source_field names must match the extracted field names, NOT the XML element structure.** + ## Output Format Provide the configuration as ONLY a properly formatted JSON document. @@ -250,4 +306,4 @@ field.enum_values|join(', ') }}]{% endif %} Analyze the XML structure and produce a Structured Data Descriptor by diagnosing the following data sample. Pay special attention to XML hierarchy, element patterns, and generate appropriate XPath expressions: -{{sample}} \ No newline at end of file +{{sample}}