ELECTE 4.0 is live — the AI Agent is here.See what shipped
Data & analytics15 min read

Reading and analyzing XML files: an operational guide for SMEs

Learn how to read XML files with simple methods and programming approaches. From FatturaPA to data analysis, our guide shows you how. Get started now!

Leggere e analizzare file XML: guida operativa per PMI

Summarize This Article with AI

An XML file arrives via PEC. You open it in a browser, see a wall of tags, and think the problem is “reading it.” In reality, that's only the first obstacle. The real problem in a company is different: understanding whether that data is correct, consistent and ready to go into your reports.

For many Italian SMEs, this topic is no longer strictly technical. Since electronic invoicing became mandatory, XML has become part of the daily work of administration, management control and analysis. It's not enough to view the document. You need to be able to tell a readable file from a reliable one. You need to know when a quick check is enough and when you need parsing, validation and normalization before loading data into Excel, into your BI tool, or into an analytics platform.

If you're looking for a practical guide on how to read XML files, this is the right path: start with simple methods, understand where they break down, then build a workflow that turns raw XML into data useful for the business. That's where errors get reduced and the time between “I have the file” and “I have a usable insight” gets shorter.


Table of contents

What an XML File Is and Why It's Essential for Businesses

An XML file organizes data in a hierarchical structure. There's a main element, there are nested sections, and each block describes a piece of information with a precise meaning. For those managing administrative processes, this detail makes the difference between readable data and data that is truly usable.

The point isn't “opening” the file. The point is understanding whether that file can flow without errors into control, accounting and analysis processes.


Understanding the structure without being a developer

Take an electronic invoice. Within the same file you'll find supplier data, customer data, taxable amounts, VAT, line items, payment terms, order references, and often exceptions that complicate reading. In XML, this information isn't laid out one under the other as in a plain spreadsheet. It's placed in precise positions, and that position explains what it represents.


For a manager, the useful distinction isn't between tags and attributes in a theoretical sense. It's between isolated data and reliable data. Reading “1000.00” out of context doesn't help much. Reading it in the correct spot in the file lets you understand whether it's the document total, the taxable amount, the tax, or the value of a single line.

This is where the first operational advantage comes from. XML preserves the context of the data.

Practical rule: reading an XML file well means verifying the meaning of the value, not just the value.


Why XML is an operational topic for administration, finance and analytics

In Italy this topic became concrete with the spread of electronic invoicing. In the FatturaPA format, XML became the standard for fiscal documentation. As a result, reading it is no longer just an IT matter. It involves administration, management control, purchasing, and anyone who needs to use that data to make decisions.

In practice, I always see the same problem. The file exists, the data is there, but the time to turn it into useful information stretches too long. Someone opens the XML, checks it visually, copies values into Excel, fixes inconsistent fields, renames suppliers written in different ways, and tries to rebuild spending categories that the file doesn't expose in a form ready for analysis. The cost isn't just operational. It's lost time-to-insight.

With FatturaPA the risk is even more evident. Two formally correct files can create the same analysis problems if one uses very messy line descriptions, if order references are incomplete, or if supplier master data comes in with different variants. At that point the problem isn't reading XML. The problem is preventing valid fiscal data from becoming unreliable management data.

A common mistake is treating XML as an attachment to view. In a company, it works better to consider it a structured data source to check before it feeds reports, dashboards and spending models. If this stage is handled poorly, the finance team ends up discussing numbers that look precise but are built on inconsistent classifications.

The right questions, at the start, are these:

  • The field I'm reading actually serves the process I need to manage
  • The file is formally valid
  • The data is consistent across different sections of the document
  • The information can be extracted without losing context
  • Master data and descriptions are clean enough for analysis

These are very concrete checks. They exist to prevent duplicate suppliers in reports, misread VAT, incompletely populated cost centers, and slow month-end reconciliations.

This is where the gap between technical reading and business value becomes clear. A parser reads the file. A well-designed process produces clean, comparable data that's ready for analysis. Platforms like ELECTE were built specifically to close this gap, reducing the manual work that stands between the XML you received and the insight you need to make better decisions.


Quick Ways to View XML Files Without Writing Code

For quick checks on a single file, you don't need parsers or libraries. What matters is understanding whether you're doing a visual check of a few fields, or whether you're already handling data that will end up in accounting, reporting, or management control. This difference matters, especially with FatturePA invoices. A check done carelessly today can turn into a wrong line in tomorrow's supplier dataset.



When a quick view is enough

Browsers, text editors and dedicated viewers solve a specific problem: quickly reading content without setting up a technical workflow. For a single file, this is often enough. You can open an XML in Chrome, Edge or Firefox to see the structure, or use Notepad, WordPad or TextEdit if you want to inspect the tags directly. In the case of electronic invoices, a dedicated viewer makes headers, document lines, taxable amount and VAT easier to read.

Here's the practical point:

ToolUseful forMain limitation

Browser

Quick visual check of the structure

Doesn't verify consistency between fields and sections

Text editor

Direct inspection of tags

Becomes cumbersome on long or nested files

Excel

Preliminary check in tabular format

Handles hierarchies and repetitions poorly

Dedicated viewer

Clearer reading of invoices and tax documents

Doesn't prepare data for analysis or automation

If you need to check the document date, VAT number, invoice total or presence of attachments, these tools are adequate.

If instead the goal is to compare suppliers, classify expenses or feed a dashboard, simple visualization slows the work down and leaves too much room for manual errors. It's the classic gap between seeing a file and arriving at reliable data within a useful timeframe.

Opening an XML doesn't equate to validating the data you'll use in reports.

Another practical point concerns volume. Ten files can even be checked by hand. Hundreds of FatturePA cannot. In that case it's worth thinking about a repeatable workflow or tools that read the content in a structured way, for example through APIs to acquire and manage tax documents in an integrated way.


The special case of signed XML files

In Italy the recurring problem isn't opening a .xml, but understanding what to do when a .xml.p7m arrives via PEC (certified email). You need to distinguish between simple XML files and digitally signed files. The second case requires tools capable of reading the signature, extracting the content and displaying the correct XML, as explained in this guide dedicated to XML and XML P7M in PEC.

Here mistakes cost time:

  • If you receive a signed file, first check the format and the signature.
  • If you use a viewer, verify that it also supports P7M, not just XML.
  • If the document enters an archive or a compliance process, the digital signature is part of the document control.

For an administrative staff member, the most useful sequence is simple:

  1. Open the PEC and identify the type of attachment.
  2. If it's a simple XML, do a quick check of the key fields.
  3. If it's a P7M, use a tool that displays the signed content in a readable way.
  4. If that data needs to feed analysis or reconciliations, visual reading alone isn't enough.

These methods do their job well in first-level checks. They don't solve the problem that really weighs on a company: turning tax XMLs, often irregular or inconsistent, into clean and comparable data without lengthening the time between receiving the document and getting useful information.


Reading and Processing XML Files with Programming

When files start piling up, manual work stops being sustainable. At that point, reading XML files with code isn't an elegant choice. It's the first step to avoid repetitive tasks, copy errors and inconsistent datasets.



The technical workflow that holds up over time

A solid approach to reading XML always follows the same logic: parsing, normalization, targeted extraction. In Java and Android tutorials, the correct flow goes through parse(), tree normalization with doc.getDocumentElement().normalize() and then retrieving fields with getElementsByTagName, a more stable method than simple viewing in a text editor, as shown in this technical tutorial on reading XML data.

This sequence matters more than the language you choose. If you skip normalization, if you search for nodes too naively, or if you assume a tag always appears only once, your script will work on some files and fail on exactly the ones that matter.

For projects that then need to communicate with external systems, it can be useful to build a replicable and documented extraction workflow. If you're working on application integrations, a useful starting point is the documentation on ELECTE APIs with verified Postman profile, especially to understand how to connect an already clean dataset to subsequent processes.


Practical examples in different languages

Below you'll find minimal examples. The goal isn't to cover every case, but to show you the basic logic: open the file, find a node, print a value.

Python

import xml.etree.ElementTree as ETtree = ET.parse("fattura.xml")root = tree.getroot()numero = root.find(".//Numero")if numero is not None:print(numero.text)

Python is often the fastest choice for prototypes, transformations, and lightweight pipelines. It's great when you need to read many XML files, extract a few fields, and save them to CSV or JSON.

JavaScript in the browser

const xmlString = `<fattura><Numero>123</Numero></fattura>`;const parser = new DOMParser();const xmlDoc = parser.parseFromString(xmlString, "application/xml");const numero = xmlDoc.getElementsByTagName("Numero")[0];console.log(numero.textContent);

This approach is useful for quick in-page tests or small internal tools. It's fine for lightweight interfaces, less so for structured back-office workflows.

Node.js with xml2js

const fs = require("fs");const xml2js = require("xml2js");const xml = fs.readFileSync("fattura.xml", "utf8");xml2js.parseString(xml, (err, result) => {if (err) throw err;console.log(result.fattura.Numero[0]);});

If you work server-side and want to build automations, Node.js remains a practical choice. The advantage is easily integrating XML reading with the file system, processing queues, and internal services.

Java with DOM

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder = factory.newDocumentBuilder();Document doc = builder.parse("fattura.xml");doc.getDocumentElement().normalize();NodeList lista = doc.getElementsByTagName("Numero");if (lista.getLength() > 0) {System.out.println(lista.item(0).getTextContent());}

Java is often present in enterprise contexts, management systems, and middleware. Here the key point isn't just reading the data, but doing it in a predictable and maintainable way.

R

library(XML)doc <- xmlParse("fattura.xml")numero <- xpathSApply(doc, "//Numero", xmlValue)print(numero)

R makes sense when parsing is part of an analytical workflow. If your next step is a statistical analysis or data preparation, you can keep everything in the same environment.

If your team opens the same files every week and repeats the same checks, you're already in automation territory.

The real gain isn't “reading XML with code.” It's removing mechanical work from people and building a workflow that produces consistent datasets.


Overcoming Advanced Challenges with Complex, Large-Scale XML Files

Serious problems start when there's more than one file. A single FatturaPA is manageable almost always. The difficulty shows up when you need to consolidate months of documents, different suppliers, inconsistently filled fields, and embedded attachments.


When the file isn't large but the volume is

In Italian SMEs, the most common case isn't the isolated “mega file,” but the batch. An annual export of incoming invoices can produce a structure with over 380,000 nodes across 4,200 invoices, including headers, detail lines, payment data, and base64-encoded attachments. In these scenarios the problem isn't opening the document. It's transforming heterogeneous XML files into a consistent dataset.

This is where a technical choice comes into play that has business effects. In a .NET environment, Microsoft states that XmlDocument loads the document into memory and is useful for reading and modifying, while for large files or read-only operations it's better to lean toward more efficient approaches such as streaming parsers or XPathDocument, to avoid excessive RAM consumption, as specified in the Microsoft documentation on reading XML with XmlDocument and XPathDocument.

In practice:

  • DOM or XmlDocument works well when you need to navigate the tree freely.
  • Streaming or XmlReader is more suitable when volume grows and you're interested in sequential reading.
  • XPathDocument is a good option when you're only reading and want more efficiency.

The trade-off is simple. The in-memory model lets you develop faster. The streaming model holds up better in production when files become numerous or heavy.


Technical validation and semantic validation

Many teams stop at XSD validation. It's useful, but it's not enough. A file can comply with the schema and still produce dirty data downstream.

Typical examples from operational work:

Type of checkWhat it verifiesWhy it matters

Structural

Tags, format, hierarchy

Prevents parsing errors

Semantic

Logical consistency of data

Prevents incorrect analysis

Operational

Presence of fields needed for reporting

Prevents unusable datasets

The trickiest case is this: ImportoTotaleDocumento formally valid but inconsistent with the sum of the line items, perhaps due to rounding logic in the supplier's management system. Or VAT codes that are formally allowed but inconsistent with the nature of the transaction.

A formally correct file can still contaminate your reporting.

There's another well-known trap in FatturaPA. The DatiBeniServizi tag contains free-text descriptions. The same cost item can appear in many different ways, with clean, abbreviated, or cryptic text. If you don't introduce a normalization step, any analysis by expense category becomes fragile.

This is why, in serious workflows, reading the file is only level one. Level two is always a set of consistency and cleaning rules. That's where data quality is protected, not in the parser.


How to Transform XML into Data Ready for CSV or JSON Analysis

A well-parsed XML file is not yet a usable dataset. It's a structured document. To do analysis, comparisons, groupings, and dashboards, you almost always need to convert it into a format that's simpler to work with.



Why the XML file isn't the final product

This is the point many processes underestimate. The bottleneck is rarely pure parsing. A decent library reads an XML file quickly. Time is lost interpreting the structure, extracting the relevant fields, cleaning, normalizing, and loading into an analytics tool.

For this reason, converting to CSV or JSON isn't a nicety. It's a central operational step. If you skip this phase and work directly on the raw file, you'll almost always end up with manual checks, improvised columns and logic that's hard to replicate.

A useful reference for anyone who works frequently between XML and spreadsheets is this guide on how to move from XML to Excel in a more orderly way.


Two useful outputs for analysts

The right format depends on how you'll use the data afterward.

CSV for tabular analysis

CSV works well when you want one row per document, or one row per invoice detail line, and then plan to use Excel, Power Query or BI tools.

Python example:

import xml.etree.ElementTree as ETimport csvtree = ET.parse("fattura.xml")root = tree.getroot()with open("fatture.csv", "w", newline="", encoding="utf-8") as f:writer = csv.writer(f)writer.writerow(["numero", "data"])numero = root.findtext(".//Numero")data = root.findtext(".//Data")writer.writerow([numero, data])

The advantage is simplicity. The limit is that you need to decide carefully how to flatten the hierarchy. If an invoice has multiple detail lines, you need a clear choice about granularity and the linking key.

JSON for semi-structured data

JSON is better suited when you want to preserve part of the hierarchical structure.

JavaScript example:

const record = {numero: "123",data: "2024-01-15",righe: [{ descrizione: "Servizio", importo: "100.00" }]};console.log(JSON.stringify(record, null, 2));

Use it when your next step is an API, a data lake, or an application that works well with nested objects.

Here's a practical rule that helps:

  • CSV if your goal is tabular reporting and classic business analysis
  • JSON if you need to preserve more complex relationships or pass data to other systems
  • Both if the process has an integration phase and an analysis phase

The XML file is the container. CSV and JSON are the formats that make the content truly workable.

If you want to reduce time-to-insight, this is where it pays to invest in method. Not in finding a more convenient viewer, but in defining a stable, repeatable transformation.


From XML to Strategic Insight with an Analytics Platform

Once the file has been read, validated and transformed, the nature of the work changes. You're no longer fighting with tags. You're finally reasoning about costs, anomalies, suppliers, spending categories and operational trends.



The bottleneck is data preparation

In real-world work, the value isn't in parsing time. It's in the time separating the raw file from information you can act on. With a manual workflow, someone has to open the document, understand the structure, extract the fields, clean the values, normalize text, and then build reports. It's a fragile process.

A classic example in FatturaPA is the free text in DatiBeniServizi. The same service can be described in many different ways by different suppliers. If you import that data without a coherent mapping, cost category analysis produces useless aggregations.

That's why, before the analytics platform, you need a data preparation layer:

  • Description normalization
  • Category mapping
  • Consistency checks
  • Stable structure for import

When this stage is done well, any analytics platform works better. If you want to explore the decision-making and visual side of this step, the resource on how to build stories with data is useful because it shows how a clean dataset becomes a narrative that helps decision-makers.


From clean dataset to decision

At this point, the XML file stops being a technical problem and becomes raw material for insight. A well-prepared dataset can fuel spend analysis, trend monitoring, deviation detection, and exception review.

To choose a platform suited to this last mile, it helps to compare what a modern business analytics software offers versus purely manual workflows based on spreadsheets and pivot tables.

Here the right criterion isn't “can it open XML?”. That's the bare minimum. The useful question is another one:

QuestionWhy it matters

The data comes in already clean

You avoid precise insights based on wrong data

Categories are consistent

You can actually compare suppliers and periods

Anomalies surface immediately

You reduce time lost on manual checks

The report is readable by business and finance

You speed up decision-making

The difference between an immature process and a mature one isn't the ability to read XML files. It's the ability to turn them into a reliable data foundation, one that doesn't force the team to redo the same work every time.


Key Takeaways

If you need to read XML files in a way that's useful to the business, keep this checklist in mind. It's more concrete than any technical definition and helps you choose the right method without wasting time.


Choose the tool based on the purpose

Don't always use the same approach. Browsers, editors and viewers are fine for quick checks. Parsers and scripts are needed when the file has to feed repeated processes. If you confuse viewing with data processing, you risk building reports on fragile foundations.


Treat signed files as a separate case

.xml.p7m files require a specific signature-handling step. If the content comes from certified email (PEC), this check isn't optional. It's part of correctly reading the document.


Don't stop at technical validation

A schema being respected doesn't guarantee a healthy dataset. Logical inconsistencies, such as misaligned totals or ambiguous tax classifications, are what most often ruin the analysis. Semantic validation is what separates an “acceptable” file from reliable data.


Convert early into an analyzable format

CSV and JSON aren't a cosmetic step. They're the point where the XML becomes workable by analytics tools, spreadsheets, pipelines and reports. The sooner you define this transformation, the more you cut manual work and improvisation.


Remember what the real goal is

Your goal isn't to read XML files. It's to get useful insights without polluting the system with dirty data. If the workflow doesn't produce a coherent dataset, the problem isn't in the final dashboard. It's much further upstream.

In practice, you can use this mini-checklist before every new project:

  • Define the end use before choosing the tool
  • Handle P7M and XML separately
  • Validate structure and meaning
  • Normalize free-text fields
  • Export to CSV or JSON before analysis

If you want to turn already-prepared data into clear, actionable insights, ELECTE helps SMEs move from a clean dataset to smart reporting, with an approach that's accessible even to non-technical teams. It's the fastest way to close the gap between operational data and decision-making.

Comments

No comments yet — start the conversation.