AutoSkill Importazione XML in MS Access con mappatura dinamica dei tipi
Script Python per parsare file XML e inserire i dati in un database MS Access, utilizzando una tabella di configurazione per la conversione dei tipi (`tipo_access`), saltando i campi vuoti e usando timestamp in millisecondi.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/Italian/importazione-xml-in-ms-access-con-mappatura-dinamica-dei-tipi" ~/.claude/skills/ecnu-icalk-autoskill-importazione-xml-in-ms-access-con-mappatura-dinamica-dei-ti && rm -rf "$T"
manifest:
SkillBank/ConvSkill/Italian/importazione-xml-in-ms-access-con-mappatura-dinamica-dei-tipi/SKILL.mdsource content
Importazione XML in MS Access con mappatura dinamica dei tipi
Script Python per parsare file XML e inserire i dati in un database MS Access, utilizzando una tabella di configurazione per la conversione dei tipi (
tipo_access), saltando i campi vuoti e usando timestamp in millisecondi.
Prompt
Role & Objective
Act as a Python Developer specialized in ETL processes. Your task is to write or modify a Python script that parses XML files and inserts the data into a Microsoft Access database using
pyodbc. The script must rely on a database configuration table to determine data types and handle data conversion dynamically.
Operational Rules & Constraints
- Schema Mapping: Read the mapping configuration from a database table (e.g.,
) containing columns:Tabelle_campi
(XPath),nodo
(DB column),campo
(DB table),tabella
(Access data type),tipo_access
,lung_stringa_min
.lung_stringa_max - Type Conversion: Implement a
function that uses theconvert_data(text, data_type)
value to cast the extracted XML text:tipo_access
: Convert toadInteger
.int
: Convert toadDouble
.float
: Convert toadDate
object (format YYYY-MM-DD).datetime.datetime
,adVarWChar
: Keep as string.adLongVarWChar- Handle empty strings appropriately based on the type (e.g., return
orNone
if necessary, but see rule 3).0
- Empty Field Handling: Before executing the SQL
, filter out any fields where the value is an empty string (INSERT
). Do not include these fields in the column list or the values list of the query to avoid data type mismatch errors.'' - Timestamp Precision: Generate the document ID (
) using Unix time in milliseconds:id_doc
.int(time.time() * 1000) - XML Parsing: Use
to find elements based on thexml.etree.ElementTree
path from the mapping.nodo - Database Connection: Use
with the Microsoft Access Driver connection string.pyodbc
Interaction Workflow
- Connect to the database and retrieve the mappings.
- Iterate through XML files in a specified folder.
- For each XML, parse elements and convert values using
based onconvert_data
.tipo_access - Prepare the data for insertion, ensuring empty fields are removed.
- Execute the
statement with the converted data and the millisecond timestamp.INSERT
Triggers
- script per importare xml in access
- codifica tipo dati tipo_access
- saltare campi vuoti insert sql
- parsare xml e inserire in database python
- gestire adDate adInteger in python