Easy XM L - XM L Parser
Info
The Easy XM L - XM L Parser is a Library for MetaTrader 5 that main purpose and abilities easyxml is a simple yet powerful xml parser which can read and parse xml from three different sources:url file input string input it is written completely in native mql5 and relies on the windows native "wininet. dll" only for fetching XML documents from an URL.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Easy XM L - XM L Parser
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
Main purpose and abilities EasyXML is a simple yet powerful XML Parser which can read and parse XML from three different sources:URL File Input String Input It is written completely in native MQL5 and relies on the Windows native "wininet.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: Xml Parser - another powerful library for MetaTrader 5 traders.
Main purpose and abilities
EasyXML is a simple yet powerful XML Parser which can read and parse XML from three different sources:
Also recommended: XM L parser - similar library with strong performance on MetaTrader 5.
URLFile Input
String Input
It is written completely in native MQL5 and relies on the Windows native "wininet.dll" only for fetching XML documents from an URL.
EasyXML will read XML as well as XHTML with (nearly) infinite node depth, as long as the document you are trying to parse is well-formed. It does
not
, however, validate the XML against a DTD or XSLT Stylesheet.
MQL5 Integration
EasyXML's Node Classes are inherited from the MQL5 native and nodes are stored in a .
When walking the DOM tree nodes can be manipulated easily by using the public EasyXML methods as well as the MQL5 native functions to retrieve data from and store data to the DOM.
URL File Caching and Debugging
Since one can not always rely on RSS Feed Uptimes, EasyXML can store a XML cache file of the Feed, once it has loaded it from a URL successfully for the first time. The user then can use the cache file instead of the Live Feed for parsing, should the Feed be down for some reason.
Since XML and XHTML documents tend to be erroneous, EasyXML has a debugging option. While it can not repair broken XML, it surely will help to detect where the error is. If turned on it will print detailed information of the nodes parsed.
Besides that, any errors that occur will always be tracked and printed, despite the fact, if debugging is turned on or off.
Basic Usage
Just include the base class in your scripts and you're set up and ready to go:
First, in your script, create an an instance of the EasyXML Class. Then set debugging and/or file caching and call one of the available methods to load the XML and start parsing:
For demonstration purposes all of the three methods are shown. Normally you won't need all of them at once, although it is possible to clear the DOM tree in between and start parsing over again, even from another source. Just use the Clear() Command to erase the parsed DOM tree. setDebugging() and setUrlCacheFile() are optional and don't have to be called if they are not needed.
EasyXmlDocument.getDocumentRoot() will always return the root node of the DOM tree. All nodes including the root node are of type CEasyXmlNode, which itself derived from the MQL5 CObject (as mentioned before). From here on all of the methods of EasyXml as well as from CArrayObj and CObject may be used side by side to walk the parsed DOM tree.
The following example shows the implementation of readRecursive(), the global function which is called in the last code example:
Recursive reading of XML documents has big advantages over inline reading, although it may not be suitable for all needs. Calling Attributes() on a node will fetch all parsed Attributes while Children() will get the child nodes stored in the actual node. Both methods return a CArrayObj containing the elements. Calling Total() on those objects can be used in a for() loop to iterate over the elements. getName() and getValue() will return actual content stored in the node.
Of course it is possible to iterate over nodes inline as well:
Iteration works just as in the recursive example, except that a separate for() loop has to be established for each and every node level to be read.
Besides that it is also possible to walk the DOM step by step and manipulate single elements if needed:
Here all of the available EasyXML methods as well as the native MQL5 Iteration/Getter/Setter of CObject and CArrayObj come in play.
Keep in mind, though, that some of those functions don't care about valid memory access and just return NULL, if they don't succeed.
In the last example calling ChildNode.Next() on the sibling node - without checking for pointer validity - would entail a serious bad pointer fault (= bad memory access), that will definitely crash the script. So if you ever have the need to step or manipulate the DOM tree manually, take care of pointer validity, as long as it concerns the CObject and CArrayObj class methods.
Most important node getters
Most important node setters For more possibilities of dealing with nodes and node arrays please be sure to also read the documentation on and .
Attribute getters/setters
Attribute Objects implements the same get/setName(), get/SetValue() methods to store and retrieve data just like the node objects.
Disclaimer
This piece of code is under active development, and, as with all software, does not claim to be free of bugs or other defects. Use EasyXml at your own risk and test thoroughly before implementing this library into any live trading EA. If you encounter any problems or have questions regarding the usage, please feel free to contact me.
Credits
The Integration of the wininet.dll used for fetching URL content uses by . Although this library is build upon its own, unique parsing system, the written by was a great learning source for dealing with MQL5 string operations.
You may also like: Easy And Fast GU I library for creating graphical interfaces - excellent alternative for library users on MetaTrader 5.
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.