Parsing XML Using External Libraries (fast-xml-parser Example)
You can integrate external data in XML format into your graphics using a third party library that converts XML to JSON. In this example we will show you how you can achieve this using the fast-xml-parser library that is fast, lightweight, and compatible with UI Builder’s scripting environment.
Note
You need a reachable HTTP endpoint that returns XML (for testing you can use a local server, e.g. http-server . --cors from a folder with your .xml file).
Installation
- Online (CDN):
loadLibrary("https://cdnjs.cloudflare.com/ajax/libs/fast-xml-parser/5.2.5/fxparser.min.js"); - Offline:
- Download
fxparser.min.js - Place it in:
C:\ProgramData\Erizos\Erizos Studio\Resources\Libs - Load it using:
loadLibrary("fxparser.min");
- Download
Example Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
Troubleshooting
| Problem | Cause | Solution |
|---|---|---|
undefined values |
Wrong object path | Use console.log(parsed) to inspect structure |
| Parsing failure | Invalid XML formatting | Validate the XML source |
| Network error | URL blocked / offline server | Check access or firewall |
| CORS errors | External source blocked request | Use same-origin source or enable backend proxy |
Summary
Using fast-xml-parser allows UI Builder scripts to convert XML into JavaScript objects. Once parsed, you can map values to UI components the same way as JSON.