MetaTrader 5 / Kütüphaneler

XML ayrıştırıcı - MetaTrader 5 için kütüphane

16
(32)

XML belgelerini ayrıştırmak için kütüphane. Üçüncü taraf kütüphaneleri kullanmadan MQL5'te uygulama.

Kütüphaneyi projelerinize bağlamak için bir önişlemci komutu eklemeniz yeterlidir

#include <Xml\XmlBase.mqh>

Kullanım örneği:

#include <Xml\XmlBase.mqh> CXmlDocument doc; void OnStart() {   string file = "File.xml";   string err;   if (doc.CreateFromFile(file,err))   {     CXmlElement * xmlItem = doc.FDocumentElement.GetChild(0);     for (int i=0; i<xmlItem.GetChildCount(); i++)     if (xmlItem.GetChild(i).GetName() == "LAYER")     {       CXmlElement* layer = xmlItem.GetChild(i);       for (int j=0; j<layer.GetChildCount(); ++j)       {                 if (layer.GetChild(j).GetName() == "NEURON")         {            /* .... */         }       }     }   } } 

Notlar:

  • Bu kütüphane, sınıf kurucularının parametre kabul edemediği o uzak zamanlarda oluşturulmuştur;
  • Sadece Xml standardının temel işlevselliği uygulanmıştır;
  • Yorumlar, düzeltmeler, eklemeler, genişletmeler memnuniyetle karşılanır.

Ana bileşenler:

CXmlDocument sınıfı - belgelerin bir dosyadan/dizeden yüklenmesini ve değişikliklerin dosyaya kaydedilmesini sağlar.

CreateX fonksiyonları belgeleri ayrıştırır ve FDocumentElement aracılığıyla erişilen hiyerarşik bir DOM modeli oluşturur

class CXmlDocument {   private:     void DoElementTrimText(CXmlElement &aXmlItem) ;      public:     CXmlElement FDocumentElement;     void CXmlDocument ();     void ~CXmlDocument ();     void Clear();     void CopyTo (CXmlDocument &xmlDoc);        bool  CreateFromText (const string& xml, string& err);     bool  CreateFromFile (const string filename, string& err);     bool  SaveToFile (const string filename);     string GetXml(); };

CXmlElement sınıfı, herhangi bir Xml belgesinin ana arayüzüdür. Elemanlara, niteliklerine ve içeriklerine erişim sağlar

class CXmlElement {   private:     string         FName;     CXmlAttribute* FAttributes[];     CXmlElement   *FElements[];     string         FText;     CXmlElement*   FParent;   public:       //--- kurucu yöntemler     void  CXmlElement ();     void ~CXmlElement ();     void Init (const string aName, const CXmlElement* aParent=NULL, const string aText="");     void CopyTo (CXmlElement &aDst);     virtual void Clear ();          //--- ana hizmet yöntemleri     string GetName () const;     void SetName (const string aName);     string GetText () const;     void SetText (const string aText);     CXmlElement* GetParent () const;     void SetParent (CXmlElement* aParent);          //--- öznitelik hizmeti yöntemleri     int GetAttributeCount () const;     int GetAttributeIndex (CXmlAttribute* aAttr) const;     CXmlAttribute* GetAttribute (const string aName) const;     CXmlAttribute* GetAttribute (int aPos) const;     string GetAttributeValue (const string aName) const;          CXmlAttribute* AttributeInsertAt (CXmlAttribute* aAttr, int aPos);     CXmlAttribute* AttributeAdd (CXmlAttribute* aAttr);     CXmlAttribute* AttributeInsertAfter (CXmlAttribute* aAfter, CXmlAttribute* aAttr);     CXmlAttribute* AttributeInsertBefore (CXmlAttribute* aBefore, CXmlAttribute* aAttr);     CXmlAttribute* AttributeRemove (CXmlAttribute* aAttr);     CXmlAttribute* AttributeRemove (int aPos);     void AttributeDelete (CXmlAttribute* aAttr);     void AttributeDelete (int aPos);     void AttributeDeleteAll ();        //--- çocuk servis yöntemleri     int GetChildCount() const;     int GetChildIndex (CXmlElement* aElement) const;     CXmlElement* GetChild (const string aName) const;     CXmlElement* GetChild (int aPos) const;     string GetChildText (const string aName) const;     CXmlElement* ChildInsertAt (CXmlElement* aElement, int aPos);     CXmlElement* ChildAdd (CXmlElement* aElement);     CXmlElement* ChildInsertAfter (CXmlElement* aAfter, CXmlElement* aElement);     CXmlElement* ChildInsertBefore (CXmlElement* aBefore, CXmlElement* aElement);     CXmlElement* ChildRemove (CXmlElement* aElement);     CXmlElement* ChildRemove (int aPos);     void ChildDelete (CXmlElement* aElement);     void ChildDelete (int aPos);     void ChildDeleteAll ();        string GetXml(int aLevel); };

CXmlAttribute sınıfı - özniteliklerle çalışmak için basit bir sınıf

class CXmlAttribute {   private:     string FName;     string FValue;  public:     //--- kurucu yöntemler     void CXmlAttribute ();     void ~CXmlAttribute ();     void Init (const string aName, const string aValue);     virtual void Clear ();     virtual CXmlAttribute* Clone ();          //--- hizmet yöntemleri     string GetName () const;     void SetName (const string aName);     string GetValue () const;     void SetValue (const string aValue);     };

MetaQuotes Ltd tarafından Rusçadan çevrilmiştir.
Orijinal kod: https://www.mql5.com/ru/code/712