DEV Community

Cover image for Data Extraction from External Files: INI, JSON, and XML in WebForms Core 2
Elanat Framework
Elanat Framework

Posted on

Data Extraction from External Files: INI, JSON, and XML in WebForms Core 2

A New Way to Integrate External Data Sources

In the second version of WebForms Core, after introducing the Smart Template Loading feature, it's now time for a feature that can transform the way you work with external data:

Ability to receive and process XML, JSON, and INI data from external sources (URLs).

INI, JSON, and XML in WebForms Core

Data Fetching Methods

WebForms Core version 2 introduces a set of new methods for receiving and extracting data from various sources:

Fetch.LoadLine(Url, Line)
Fetch.LoadINI(Url, Name, IsINILike = false)
Fetch.LoadJSON(Url, Name)
Fetch.LoadXML(Url, Name)
Enter fullscreen mode Exit fullscreen mode

1. LoadLine — Simple Text Extraction

Sometimes you just need a specific line from a text file.
The LoadLine method lets you fetch that line precisely and efficiently — even from remote files.

string line = Fetch.LoadLine("/data/sample.txt", 11);
form.AddText("<p>", line);
Enter fullscreen mode Exit fullscreen mode

📘 Example:
Suppose /data/sample.txt contains line-based data; this method directly retrieves line 12 (Is start from line 0) and injects it into your form.

Please note: "Fetch" is a helper class in the WebForms class on the server. You cannot add data to it. The following example will not work correctly:

string line = Fetch.LoadLine("/data/sample.txt", 11);
form.AddText("<p>", "Hello " + line);
Enter fullscreen mode Exit fullscreen mode

The correct way to operate is as follows:

form.AddText("<p>", "Hello ");
string line = Fetch.LoadLine("/data/sample.txt", 11);
form.AddText("<p>", line);
Enter fullscreen mode Exit fullscreen mode

2. LoadINI — Configuration Made Easy

Many projects use INI files for configuration.
With LoadINI, you can easily retrieve specific values from INI files or any INI-like structure.

string apiKey = Fetch.LoadINI("/config/app.ini", "Auth.ApiKey");
form.AddValue("TextBox1", apiKey);
Enter fullscreen mode Exit fullscreen mode

Parameters:

  • Url: path to the INI file or similar source
  • Name: key or nested path (e.g., Database.Connection.Server)
  • IsINILike: set to true if the file follows an INI-like structure but isn’t a strict INI format

🧩 This feature is especially useful for loading configuration values dynamically from servers or CDNs.


3. LoadJSON — Smart Data for Dynamic Content

In WebForms Core 2, you can load JSON data from any API or remote source and use any part of it directly in your templates.

string title = Fetch.LoadJSON("https://api.example.com/article.json", "article.title");
string text  = Fetch.LoadJSON("https://api.example.com/article.json", "article.content");

form.SetText("{content}-1|<h2>", title);
form.SetText("{content}-1|<p>", text);
Enter fullscreen mode Exit fullscreen mode

🧠 This method supports path-based access (similar to XPath for XML).
For example, user.profile.avatar extracts the avatar value from a nested JSON structure.

Note: Internal and external URLs fetched using these new features are not cached on the client side.
WebForms Core uses a server-managed cache layer, which must be configured on the server.
An advanced URL caching mechanism (client cache) will be introduced later in version 2.


4. LoadXML — Structured Data Extraction

For structured data like RSS feeds, sitemaps, or any XML-based source, the LoadXML method is your go-to choice.

string itemTitle = Fetch.LoadXML("https://feed.example.com/rss.xml", "/rss/channel/item[1]/title");
string itemLink  = Fetch.LoadXML("https://feed.example.com/rss.xml", "/rss/channel/item[1]/link");

form.SetText("<article>-1|<a>", itemTitle);
form.SetAttribute("-", "href", itemLink);
Enter fullscreen mode Exit fullscreen mode

📄 This method supports XPath, allowing you to extract precise elements from an XML document.


💡 Combining Templates with Data

The real power of WebForms Core emerges when external HTML templates are combined with API data.

form.AddText("<main>", Fetch.LoadHtml("/template/article.html", "Article"));
form.Replace("<main>|<h2>-1", "@ArticleTitle", Fetch.LoadJSON("/data/article.json", "title"), false, true);
form.Replace("-", "@ArticleText", Fetch.LoadJSON("/data/article.json", "content"), false, true);
Enter fullscreen mode Exit fullscreen mode

🔗 Here’s what happens:

  • The HTML template is loaded from /template/article.html.
  • Actual data is fetched from /data/article.json.
  • Everything is rendered on the client side, based on commands issued by the server.

⚙️ Designed for API-Driven Architectures

The LoadINI, LoadJSON, and LoadXML methods pave the way for creating API-driven web applications — without heavy JavaScript libraries or direct fetch calls.

Data Type Method Target Format Typical Use Case
JSON LoadJSON REST / GraphQL APIs User data, content, products
XML LoadXML RSS, SOAP, Sitemap Feeds, reports
INI LoadINI Server / Module Config Service configuration
Text LoadLine Specific text lines Logs, simple text data

🔮 Why It Matters

✅ No need to write JavaScript Fetch API or Promises
✅ All operations are controlled via server-side commands
✅ Supports multiple data formats (INI, JSON, XML)
✅ Perfect for No-JavaScript WebApps


Amazing Capabilities of Data Fetching in WebForms Core 2

When Simplicity Meets Unlimited Possibility

The new features in WebForms Core 2 aren't just for data retrieval; they open the door to a new generation of web applications — websites that are multilingual, intelligent, and data-driven, without requiring a single line of JavaScript in your code.

🌍 1. Multi-Language Websites — Powered by INI Files

Supporting multiple languages ​​has always been one of the biggest challenges in web development. In WebForms Core 2, you can easily manage different languages ​​through INI files.

Sample file "/lang/fr.ini":

[french]
about=À propos de nous
home=Accueil
link=Lien
Enter fullscreen mode Exit fullscreen mode

Sample file "/lang/fa.ini":

[farsi]
about=درباره ما
home=خانه
link=لینک
Enter fullscreen mode Exit fullscreen mode

Server code

string lang = StaticObject.CurrentLanguage;
string aboutLang  = Fetch.LoadINI($"/lang/{lang}.ini", "about");
string linkLang = Fetch.LoadINI($"/lang/{lang}.ini", "link");

form.SetText("<main>|<h3>", aboutLang);
form.SetText("<footer>|<h2>", linkLang);
Enter fullscreen mode Exit fullscreen mode

Result
The content of each page is loaded from the corresponding language file.

No need for i18n or bulky JavaScript packages.

The result? A complete multilingual translation system, with just a few lines of server-side code, running entirely on the client.

🌐 2. Live Data from External APIs

With the LoadJSON method, getting data from global APIs and displaying it on the page is as simple as substituting a variable.

Example: Live clocks for different countries

string country = "Japan";
string time = Fetch.LoadJSON($"https://worldtimeapi.org/api/timezone/Asia/Tokyo", "datetime");

form.SetText("<section>|<h2>", $"Time in {country}");
form.SetText("<section>|<p>", time);
Enter fullscreen mode Exit fullscreen mode

Result on the page:

<section>
  <h2>Time in Japan</h2>
  <p>2025-11-10T19:44:30+09:00</p>
</section>
Enter fullscreen mode Exit fullscreen mode

This data is fetched in real-time from a public API and rendered by WebFormsJS on the client side — no need for fetch() or async in JavaScript.

🧩 3. Dynamic UI Composition from APIs

Composing HTML templates and API data is now possible dynamically and simply.

For example, displaying a list of recent articles from a JSON API:

string title1 = Fetch.LoadJSON("/api/articles.json", "articles[0].title");
string title2 = Fetch.LoadJSON("/api/articles.json", "articles[1].title");

form.AddText("<main>", Fetch.LoadHtml("/template/list.html", "ListItem"));
form.Replace("<section>|<h3>", "@Title", title1, false, true);
form.Replace("<section>|<h3>1", "@Title", title2, false, true);
Enter fullscreen mode Exit fullscreen mode

Result:
A dynamic list of API data within an HTML template is rendered fully on the client.

🔄 4. Auto-Refreshing Data — Real-Time APIs

Thanks to the AssignInterval method infrastructure in WebForms Core, data retrieved from APIs can be automatically refreshed:

form.SetText("Weather|<span>", Fetch.LoadJSON("https://myexampleglobalweather.com/api/weather.json", "temperature"));
form.AssignInterval(30); // Refresh data every 30 seconds
Enter fullscreen mode Exit fullscreen mode

This means even dashboards, live statistics, and monitoring systems can be built without any additional JS.

Note: You can also use SSE and WebSocket in WebForms Core technology for internal APIs that generate real-time data.

🗺 5. XML-Driven Navigation

With the LoadXML method, you can fetch menus, sitemaps, or page paths directly from XML files or even Sitemaps:

<menu>
  <item name="Home" url="/" />
  <item name="Products" url="/products" />
  <item name="Contact" url="/contact" />
</menu>
Enter fullscreen mode Exit fullscreen mode
string name = Fetch.LoadXML("/data/menu.xml", "/menu/item[2]/@name");
string url  = Fetch.LoadXML("/data/menu.xml", "/menu/item[2]/@url");

form.AddTag("<nav>", "a");
form.SetText("<nav>|<a>-1", name);
form.SetAttribute("-", "href", url);
Enter fullscreen mode Exit fullscreen mode

Create a dynamic menu from XML — no JSON, no fetch, no JavaScript components.


In Summary — The Magic of Server Commands

Capability Method Description
Multi-language Support LoadINI Retrieve translations from language files
Live Data LoadJSON Fetch global APIs such as weather, time, or currency data
Structured Data LoadXML Use data from RSS feeds, Sitemaps, or enterprise XML sources
Dynamic Configuration LoadINI Load configuration for server, modules, or templates
Specific Text Lines LoadLine Fetch specific lines directly from text files (e.g., logs or reports)
Auto Refresh Server Command + Fetch Automatically refresh and rebuild data in real-time

The Vision

By combining LoadHtml, LoadINI, LoadJSON, and LoadXML, WebForms Core 2 is now at the point where it can:

  • Build multilingual websites
  • Display live global data
  • Create dynamic UI without JS frameworks
  • While remaining fully Server-Driven

The result:
A new world of web development, without the weight of React and without server-side limitations.


Conclusion

With these new capabilities, WebForms Core 2 doesn’t just load HTML templates from external sources — it can now fetch and inject live data from multiple data formats as well.

This marks a major step toward the Server-Command / Client-Execution Architecture:

Where the server only commands,
and the client does everything — fast, lightweight, and intelligent.

WebForms Core in GitHub: https://github.com/webforms-core

Top comments (0)