XML datasource
XML datasources allow you to fetch and display data from XML APIs, web services, RSS feeds, SOAP services, and any URL that returns XML formatted data. The system automatically parses XML structures using XPath and makes the data available to your widgets and templates.
Prerequisites
Before creating an XML datasource, ensure you have:
- A valid XML API endpoint or URL that returns well-formed XML data
- Proper network access to the XML source
- Understanding of the XML structure and namespace usage
- Authentication credentials if required by the XML API
- Knowledge of XPath expressions for complex data extraction
- Familiarity with XML schemas if validation is required
Supported XML Formats
The XML datasource supports various XML structures and standards:
Simple XML Structure:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<title>Weather Report</title>
<temperature>22°C</temperature>
<humidity>65%</humidity>
<location>New York</location>
</data>
Array-like XML (Multiple Elements):
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product>
<id>1</id>
<name>Laptop Computer</name>
<price>899.99</price>
<category>Electronics</category>
</product>
<product>
<id>2</id>
<name>Wireless Mouse</name>
<price>29.99</price>
<category>Accessories</category>
</product>
</products>
Nested XML with Attributes:
<?xml version="1.0" encoding="UTF-8"?>
<company name="Tech Corp" founded="2020">
<departments>
<department id="IT" budget="500000">
<name>Information Technology</name>
<employees>
<employee id="001" role="Developer">
<name>John Smith</name>
</employee>
</employees>
</department>
</departments>
</company>
XML with Namespaces:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:corp="http://techcorp.com/schema"
xmlns:hr="http://hr.system.com/schema">
<corp:company>
<corp:name>Tech Corporation</corp:name>
<hr:employees>
<hr:employee>
<hr:name>Jane Doe</hr:name>
<hr:position>Manager</hr:position>
</hr:employee>
</hr:employees>
</corp:company>
</root>
SOAP Response XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<GetWeatherResponse xmlns="http://weather.service.com">
<GetWeatherResult>
<Temperature>75</Temperature>
<Condition>Sunny</Condition>
<WindSpeed>5</WindSpeed>
</GetWeatherResult>
</GetWeatherResponse>
</soap:Body>
</soap:Envelope>
Create datasource
Go to Settings > Datasources and open the External Datasources tab. Click Add external datasource, then on the Choose a datasource type screen select XML.
Basic Configuration
1. Update Schedule
Set how often the datasource updates under Refresh settings: a Simple interval or an Advanced schedule (cron). Learn more: Refresh and caching
Consider the source system's update frequency. XML APIs from databases might update every few minutes, while report APIs might only update daily. Match your refresh frequency accordingly.
2. XML Endpoint URL
In the URL field, enter the XML API endpoint or URL. The URL must:
- Return valid, well-formed XML content
- Be accessible from your server without firewall restrictions
- Use HTTP or HTTPS protocol
- Respond with proper
Content-Type: application/xmlortext/xmlheaders
https://api.company.com/data.xml- REST API returning XMLhttps://weather.service.com/current?format=xml- Weather service APIhttps://internal.app.com/reports/daily.xml- Internal business reportshttps://feeds.example.com/products.xml- Product catalog feed
Advanced Configuration Options
3. Advanced settings The caching options are explained in Refresh and caching. Active, Continue refreshing despite errors, Connection settings and shuffling lists (Process and filter data) are explained in Advanced datasource settings.
Authentication
If the XML source needs authentication, click Connection settings:
- For a username and password, turn on Authentication (Basic auth).
- For an API key or a token, add it under Custom headers (advanced), for example
X-API-Keywith your key, orAuthorizationwithBearer <token>.
Learn more: Connection settings
4. Save Configuration
Once all settings are configured according to your XML source requirements, click Save to create the datasource.
After saving, check the datasource preview to ensure XML is being parsed correctly and verify the data structure matches your widget requirements. Test XPath expressions if using complex XML structures.
XML Data Structure and XPath
XML datasources provide access to XML elements, attributes, and text content through XPath expressions: