Użyłem komponentu XMLDocument z C++ Builder.
Tam jest taki Wizard jeśli go przejdziesz to dostaniesz plik jak poniżej.
Generalnie chciałem potestować przykład z youtube gdzie Gość prezentuje jak zaczytać dane z XML.
LINK
Plik z XML pobrałem gdzieś z Internetu.
#ifndef cd_catalogH
#define cd_catalogH
#include <System.hpp>
#include <Xml.Xmldom.hpp>
#include <Xml.XMLIntf.hpp>
#include <Xml.XMLDoc.hpp>
#include <XMLNodeImp.h>
// Forward Decls
__interface IXMLCATALOGType;
typedef System::DelphiInterface<IXMLCATALOGType> _di_IXMLCATALOGType;
__interface IXMLCDType;
typedef System::DelphiInterface<IXMLCDType> _di_IXMLCDType;
// IXMLCATALOGType
__interface INTERFACE_UUID("{7C861AE2-B0DE-4E2A-8FE7-DBE88969CEFD}") IXMLCATALOGType : public Xml::Xmlintf::IXMLNodeCollection
{
public:
public:
// Property Accessors
virtual _di_IXMLCDType __fastcall Get_CD(int Index) = 0;
// Methods & Properties
virtual _di_IXMLCDType __fastcall Add() = 0;
virtual _di_IXMLCDType __fastcall Insert(const int Index) = 0;
__property _di_IXMLCDType CD[int Index] = { read=Get_CD };/* default */
};
// IXMLCDType
__interface INTERFACE_UUID("{78643A82-6907-4E2C-919B-7BF30402CC43}") IXMLCDType : public Xml::Xmlintf::IXMLNode
{
public:
// Property Accessors
virtual System::UnicodeString __fastcall Get_TITLE() = 0;
virtual System::UnicodeString __fastcall Get_ARTIST() = 0;
virtual System::UnicodeString __fastcall Get_COUNTRY() = 0;
virtual System::UnicodeString __fastcall Get_COMPANY() = 0;
virtual System::UnicodeString __fastcall Get_PRICE() = 0;
virtual int __fastcall Get_YEAR() = 0;
virtual void __fastcall Set_TITLE(System::UnicodeString Value) = 0;
virtual void __fastcall Set_ARTIST(System::UnicodeString Value) = 0;
virtual void __fastcall Set_COUNTRY(System::UnicodeString Value) = 0;
virtual void __fastcall Set_COMPANY(System::UnicodeString Value) = 0;
virtual void __fastcall Set_PRICE(System::UnicodeString Value) = 0;
virtual void __fastcall Set_YEAR(int Value) = 0;
// Methods & Properties
__property System::UnicodeString TITLE = { read=Get_TITLE, write=Set_TITLE };
__property System::UnicodeString ARTIST = { read=Get_ARTIST, write=Set_ARTIST };
__property System::UnicodeString COUNTRY = { read=Get_COUNTRY, write=Set_COUNTRY };
__property System::UnicodeString COMPANY = { read=Get_COMPANY, write=Set_COMPANY };
__property System::UnicodeString PRICE = { read=Get_PRICE, write=Set_PRICE };
__property int YEAR = { read=Get_YEAR, write=Set_YEAR };
};
// Forward Decls
class TXMLCATALOGType;
class TXMLCDType;
// TXMLCATALOGType
class TXMLCATALOGType : public Xml::Xmldoc::TXMLNodeCollection, public IXMLCATALOGType
{
__IXMLNODECOLLECTION_IMPL__
protected:
// IXMLCATALOGType
virtual _di_IXMLCDType __fastcall Get_CD(int Index);
virtual _di_IXMLCDType __fastcall Add();
virtual _di_IXMLCDType __fastcall Insert(const int Index);
public:
virtual void __fastcall AfterConstruction(void);
};
// TXMLCDType
class TXMLCDType : public Xml::Xmldoc::TXMLNode, public IXMLCDType
{
__IXMLNODE_IMPL__
protected:
// IXMLCDType
virtual System::UnicodeString __fastcall Get_TITLE();
virtual System::UnicodeString __fastcall Get_ARTIST();
virtual System::UnicodeString __fastcall Get_COUNTRY();
virtual System::UnicodeString __fastcall Get_COMPANY();
virtual System::UnicodeString __fastcall Get_PRICE();
virtual int __fastcall Get_YEAR();
virtual void __fastcall Set_TITLE(System::UnicodeString Value);
virtual void __fastcall Set_ARTIST(System::UnicodeString Value);
virtual void __fastcall Set_COUNTRY(System::UnicodeString Value);
virtual void __fastcall Set_COMPANY(System::UnicodeString Value);
virtual void __fastcall Set_PRICE(System::UnicodeString Value);
virtual void __fastcall Set_YEAR(int Value);
};
// Global Functions
_di_IXMLCATALOGType __fastcall GetCATALOG(Xml::Xmlintf::_di_IXMLDocument Doc);
_di_IXMLCATALOGType __fastcall GetCATALOG(Xml::Xmldoc::TXMLDocument *Doc);
_di_IXMLCATALOGType __fastcall LoadCATALOG(const System::UnicodeString& FileName);
_di_IXMLCATALOGType __fastcall NewCATALOG();
#define TargetNamespace ""
#endif
i
#include <System.hpp>
#pragma hdrstop
#include "cd_catalog.h"
// Global Functions
_di_IXMLCATALOGType __fastcall GetCATALOG(Xml::Xmlintf::_di_IXMLDocument Doc)
{
return (_di_IXMLCATALOGType) Doc->GetDocBinding("CATALOG", __classid(TXMLCATALOGType), TargetNamespace);
};
_di_IXMLCATALOGType __fastcall GetCATALOG(Xml::Xmldoc::TXMLDocument *Doc)
{
Xml::Xmlintf::_di_IXMLDocument DocIntf;
Doc->GetInterface(DocIntf);
return GetCATALOG(DocIntf);
};
_di_IXMLCATALOGType __fastcall LoadCATALOG(const System::UnicodeString& FileName)
{
return (_di_IXMLCATALOGType) Xml::Xmldoc::LoadXMLDocument(FileName)->GetDocBinding("CATALOG", __classid(TXMLCATALOGType), TargetNamespace);
};
_di_IXMLCATALOGType __fastcall NewCATALOG()
{
return (_di_IXMLCATALOGType) Xml::Xmldoc::NewXMLDocument()->GetDocBinding("CATALOG", __classid(TXMLCATALOGType), TargetNamespace);
};
// TXMLCATALOGType
void __fastcall TXMLCATALOGType::AfterConstruction(void)
{
RegisterChildNode(System::UnicodeString("CD"), __classid(TXMLCDType));
ItemTag = "CD";
ItemInterface = __uuidof(IXMLCDType);
Xml::Xmldoc::TXMLNodeCollection::AfterConstruction();
};
_di_IXMLCDType __fastcall TXMLCATALOGType::Get_CD(int Index)
{
return (_di_IXMLCDType) List->Nodes[Index];
};
_di_IXMLCDType __fastcall TXMLCATALOGType::Add()
{
return (_di_IXMLCDType) AddItem(-1);
};
_di_IXMLCDType __fastcall TXMLCATALOGType::Insert(const int Index)
{
return (_di_IXMLCDType) AddItem(Index);
};
// TXMLCDType
System::UnicodeString __fastcall TXMLCDType::Get_TITLE()
{
return GetChildNodes()->Nodes[System::UnicodeString("TITLE")]->NodeValue.operator System::UnicodeString();
};
void __fastcall TXMLCDType::Set_TITLE(System::UnicodeString Value)
{
GetChildNodes()->Nodes[System::UnicodeString("TITLE")]->NodeValue = Value;
};
System::UnicodeString __fastcall TXMLCDType::Get_ARTIST()
{
return GetChildNodes()->Nodes[System::UnicodeString("ARTIST")]->NodeValue.operator System::UnicodeString();
};
void __fastcall TXMLCDType::Set_ARTIST(System::UnicodeString Value)
{
GetChildNodes()->Nodes[System::UnicodeString("ARTIST")]->NodeValue = Value;
};
System::UnicodeString __fastcall TXMLCDType::Get_COUNTRY()
{
return GetChildNodes()->Nodes[System::UnicodeString("COUNTRY")]->NodeValue.operator System::UnicodeString();
};
void __fastcall TXMLCDType::Set_COUNTRY(System::UnicodeString Value)
{
GetChildNodes()->Nodes[System::UnicodeString("COUNTRY")]->NodeValue = Value;
};
System::UnicodeString __fastcall TXMLCDType::Get_COMPANY()
{
return GetChildNodes()->Nodes[System::UnicodeString("COMPANY")]->NodeValue.operator System::UnicodeString();
};
void __fastcall TXMLCDType::Set_COMPANY(System::UnicodeString Value)
{
GetChildNodes()->Nodes[System::UnicodeString("COMPANY")]->NodeValue = Value;
};
System::UnicodeString __fastcall TXMLCDType::Get_PRICE()
{
return GetChildNodes()->Nodes[System::UnicodeString("PRICE")]->NodeValue.operator System::UnicodeString();
};
void __fastcall TXMLCDType::Set_PRICE(System::UnicodeString Value)
{
GetChildNodes()->Nodes[System::UnicodeString("PRICE")]->NodeValue = Value;
};
int __fastcall TXMLCDType::Get_YEAR()
{
return GetChildNodes()->Nodes[System::UnicodeString("YEAR")]->NodeValue.operator int();
};
void __fastcall TXMLCDType::Set_YEAR(int Value)
{
GetChildNodes()->Nodes[System::UnicodeString("YEAR")]->NodeValue = Value;
};