Skip to content

AppML Data Services — Connecting to Databases, XML, and JSON Sources

DodaTech Updated 2026-06-28 5 min read

In this tutorial, you will learn about AppML Data Services. We cover key concepts, practical examples, and best practices to help you master this topic.

AppML data services abstract away the connection details for different data sources, letting you switch between MySQL, SQLite, XML files, or JSON APIs by changing a single attribute in your model.

What You'll Learn

You will configure AppML data services for multiple data source types, understand how each connects, and learn when to use each type for your application.

Why It Matters

Data services let you prototype with SQLite and deploy with MySQL without changing your model. You can also combine data from a database and an external API in the same application, giving you flexibility without extra code.

Real-World Use

Durga Antivirus Pro uses AppML data services to combine threat data from a MySQL database with real-time updates from an external JSON API. The data service layer unifies both sources into a single interface for the dashboard.

flowchart LR
    A[AppML Model] --> B[Data Service Layer]
    B --> C[MySQL Service]
    B --> D[SQLite Service]
    B --> E[XML Service]
    B --> F[JSON API Service]
    B --> G[PostgreSQL Service]
    C --> H[Database]
    D --> H
    G --> H
    E --> I[XML File]
    F --> J[HTTP API]
    style B fill:#1e293b,color:#fff

MySQL Data Service

The MySQL data service connects to a MySQL or MariaDB database using PHP PDO.

<appml>
  <datasource type="mysql">
    <connection
      server="db.example.com"
      port="3306"
      database="shop"
      user="appml_user"
      password="secure_password"
    />
    <table name="customers">
      <field name="id" type="integer" key="true" autoincrement="true"/>
      <field name="name" type="string"/>
      <field name="email" type="string"/>
    </table>
  </datasource>
</appml>

Expected output: AppML connects to the MySQL database and generates CRUD operations for the customers table.

MySQL is best for production applications with multiple users, high traffic, and complex queries. It supports transactions, stored procedures, and full-text search.

SQLite Data Service

SQLite stores data in a single file, making it ideal for development, prototyping, and single-user applications.

<appml>
  <datasource type="sqlite">
    <connection file="./data/app.db"/>
    <table name="settings">
      <field name="key" type="string" key="true"/>
      <field name="value" type="text"/>
    </table>
  </datasource>
</appml>

Expected output: AppML creates the SQLite database file if it does not exist and generates the settings table.

SQLite requires no server setup, no credentials, and is portable across systems. Use it for development environments, embedded applications, and small-scale tools.

XML Data Service

XML data service reads and writes data as XML files instead of a database.

<appml>
  <datasource type="xml">
    <connection file="./data/products.xml"/>
    <table name="product">
      <field name="id" type="string" key="true"/>
      <field name="name" type="string"/>
      <field name="price" type="decimal"/>
    </table>
  </datasource>
</appml>

Expected output: AppML reads products from the XML file and generates the same CRUD interface as a database-backed model.

The XML file is human-readable and version-control friendly. Use XML data services for configuration data, small datasets, or when you want to edit data directly in a text editor.

JSON API Data Service

The JSON API data service connects to external REST APIs as a data source.

<appml>
  <datasource type="json">
    <connection url="https://api.example.com/v1/users"/>
    <table name="user">
      <field name="id" type="integer" key="true"/>
      <field name="name" type="string"/>
      <field name="email" type="string"/>
    </table>
  </datasource>
</appml>

Expected output: AppML fetches data from the API endpoint and renders it in the generated view. Create and update operations send POST and PUT requests to the same URL.

This service is read-only by default. Check the API documentation to see if it supports write operations.

Common Mistakes

  1. Using MySQL for prototyping when SQLite is faster: MySQL requires a running server, user credentials, and database creation. SQLite is instant and requires zero setup.

  2. Storing XML data files in the web root: XML files containing data should be outside the public web directory or password-protected to prevent direct access.

  3. Ignoring API rate limits with JSON data service: The JSON service sends requests to external APIs on every page load. Cache responses or use SQLite as a local cache layer.

  4. Not handling connections timeouts for remote MySQL servers: Remote database connections may time out under load. Configure connection pooling or increase the timeout value.

  5. Assuming all data services support write operations: XML files support writes. JSON APIs may be read-only depending on the endpoint. Check before building write features.

Practice Questions

  1. Which data service is best for prototyping?

SQLite. It requires no server setup, no credentials, and creates the database file automatically.

  1. How do you specify the database type in an AppML datasource?

Use the type attribute on the <datasource> element. Values include mysql, sqlite, xml, json, and PostgreSQL.

  1. What file format does the XML data service use?

Standard XML files with elements and attributes matching the table and field definitions.

  1. Can AppML combine data from multiple service types in one application?

Yes. Define multiple <datasource> elements, each with a different type. Views can reference tables from any datasource.

  1. What is the main advantage of the JSON data service?

It lets you use an external REST API as the data source without writing HTTP client code.

Challenge

Create an AppML model that uses two datasources: a SQLite database for local configuration and a JSON API for live weather data. Display both data sets in separate views on the same page.

Frequently Asked Questions

Can I switch a model from SQLite to MySQL without changing the XML?

Yes. Change the type attribute from sqlite to mysql and update the connection details. The table and field definitions remain unchanged.

Does the XML data service support large files?

The XML service loads the entire file into memory. For large datasets, use a database service instead for better performance.

How does the JSON data service handle authentication?

The connection element supports headers for API keys or bearer tokens. Configure them in the datasource definition.

Can I use PostgreSQL with AppML?

Yes. AppML supports PostgreSQL through PDO. Use type="postgresql" in the datasource definition.

What happens when the database connection fails?

AppML displays a user-friendly error page with the connection details hidden. The full error is logged server-side for debugging.

Mini Project

Create a product catalog with three datasources: SQLite for product details, XML for supplier information, and a JSON API for real-time pricing. Build a view that combines all three into a single product listing.

What's Next

Continue to XML Data to learn how to work with XML data sources in detail, including structure, querying, and editing XML files through AppML.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro