C++ XML-Datenbindung Embarcadero RAD Studio XE xml speichern
-
Hallo,
ich versuche mich momentan etwas an C++ mit dem Embarcadero RAD Studio XE (30 Tage Testversion). Dort gibt es ein Generator für eine XML-Datenbindung.
Daten aus der XML Datei zu lesen schaffe ich auch momentan.
Nur ich verzweifle ich gerade daran die geänderten Werte wieder in die XML Datei zurückschreiben._di_IXMLDATAType pFile; pFile = LoadDATA("C:\\test.xml"); ShowMessage(pFile->DATAs[0].DATA[1]->Wert); //Wert wo in der XML Steht anzeigen pFile->DATAs[0].DATA[1]->Wert= "test 0001"; //Wert verändern ShowMessage(pFile->DATAs[0].DATA[1]->Wert); //Veränderten Wert anzeigen
Wie kann ich die Änderung wieder zurückschreiben,
bzw. gibt es was besseres als den "XML-Datenbindung Experten" oder sollte ich Informationen von einem Programm ganz anders Speicher?Schonmal Danke für eure Antworten.
PS:
xml:<?xml version="1.0" encoding="ISO-8859-1" ?> <Container> <Allgemein> </Allgemein> <DATAs> <DATA> <Wert>123456abc</Wert> <bla>ffdffc</bla> </DATA> <DATA> <Wert>123456abc</Wert> <bla>ffdffc</bla> </DATA> <DATA> <Wert>123456abc</Wert> <bla>ffdffc</bla> </DATA> </DATAs> </Container>
XML-Datenbindung:.ccp:
// *********************************************** // // // XML-Datenbindung // // *********************************************** // #include <vcl.h> #pragma hdrstop #include "test.h" // Globale Funktionen _di_IXMLContainerType __fastcall GetContainer(_di_IXMLDocument Doc) { return (_di_IXMLContainerType) Doc->GetDocBinding("Container", __classid(TXMLContainerType), TargetNamespace); }; _di_IXMLContainerType __fastcall GetContainer(TXMLDocument *Doc) { _di_IXMLDocument DocIntf; Doc->GetInterface(DocIntf); return GetContainer(DocIntf); }; _di_IXMLContainerType __fastcall LoadContainer(const UnicodeString& FileName) { return (_di_IXMLContainerType) LoadXMLDocument(FileName)->GetDocBinding("Container", __classid(TXMLContainerType), TargetNamespace); }; _di_IXMLContainerType __fastcall NewContainer() { return (_di_IXMLContainerType) NewXMLDocument()->GetDocBinding("Container", __classid(TXMLContainerType), TargetNamespace); }; // TXMLContainerType void __fastcall TXMLContainerType::AfterConstruction(void) { RegisterChildNode(UnicodeString("DATAs"), __classid(TXMLDATAsType)); TXMLNode::AfterConstruction(); }; UnicodeString __fastcall TXMLContainerType::Get_Allgemein() { return TXMLNode::ChildNodes->Nodes[UnicodeString("Allgemein")]->Text; }; void __fastcall TXMLContainerType::Set_Allgemein(UnicodeString Value) { TXMLNode::ChildNodes->Nodes[UnicodeString("Allgemein")]->NodeValue = Value; }; _di_IXMLDATAsType __fastcall TXMLContainerType::Get_DATAs() { return (_di_IXMLDATAsType) TXMLNode::ChildNodes->Nodes[UnicodeString("DATAs")]; }; // TXMLDATAsType void __fastcall TXMLDATAsType::AfterConstruction(void) { RegisterChildNode(UnicodeString("DATA"), __classid(TXMLDATAType)); ItemTag = "DATA"; ItemInterface = __uuidof(IXMLDATAType); TXMLNodeCollection::AfterConstruction(); }; _di_IXMLDATAType __fastcall TXMLDATAsType::Get_DATA(int Index) { return (_di_IXMLDATAType) TXMLNodeCollection::List->Nodes[Index]; }; _di_IXMLDATAType __fastcall TXMLDATAsType::Add() { return (_di_IXMLDATAType) AddItem(-1); }; _di_IXMLDATAType __fastcall TXMLDATAsType::Insert(const int Index) { return (_di_IXMLDATAType) AddItem(Index); }; // TXMLDATAType UnicodeString __fastcall TXMLDATAType::Get_Wert() { return TXMLNode::ChildNodes->Nodes[UnicodeString("Wert")]->Text; }; void __fastcall TXMLDATAType::Set_Wert(UnicodeString Value) { TXMLNode::ChildNodes->Nodes[UnicodeString("Wert")]->NodeValue = Value; }; UnicodeString __fastcall TXMLDATAType::Get_bla() { return TXMLNode::ChildNodes->Nodes[UnicodeString("bla")]->Text; }; void __fastcall TXMLDATAType::Set_bla(UnicodeString Value) { TXMLNode::ChildNodes->Nodes[UnicodeString("bla")]->NodeValue = Value; };
.h
// *********************************************** // // // XML-Datenbindung // // *********************************************** // #ifndef testH #define testH #include <System.hpp> #include <xmldom.hpp> #include <XMLDoc.hpp> #include <XMLIntf.hpp> #include <XMLNodeImp.h> // Forward-Deklarationen __interface IXMLContainerType; typedef System::DelphiInterface<IXMLContainerType> _di_IXMLContainerType; __interface IXMLDATAsType; typedef System::DelphiInterface<IXMLDATAsType> _di_IXMLDATAsType; __interface IXMLDATAType; typedef System::DelphiInterface<IXMLDATAType> _di_IXMLDATAType; // IXMLContainerType __interface INTERFACE_UUID("{C21DC57C-A4E9-4141-9B9E-3144335B8BC8}") IXMLContainerType : public IXMLNode { public: // Eigenschaftszugriff virtual UnicodeString __fastcall Get_Allgemein() = 0; virtual _di_IXMLDATAsType __fastcall Get_DATAs() = 0; virtual void __fastcall Set_Allgemein(UnicodeString Value) = 0; // Methoden & Eigenschaften __property UnicodeString Allgemein = { read=Get_Allgemein, write=Set_Allgemein }; __property _di_IXMLDATAsType DATAs = { read=Get_DATAs }; }; // IXMLDATAsType __interface INTERFACE_UUID("{2F25A785-6757-4B5F-846F-1572C442B11D}") IXMLDATAsType : public IXMLNodeCollection { public: public: // Eigenschaftszugriff virtual _di_IXMLDATAType __fastcall Get_DATA(int Index) = 0; // Methoden & Eigenschaften virtual _di_IXMLDATAType __fastcall Add() = 0; virtual _di_IXMLDATAType __fastcall Insert(const int Index) = 0; __property _di_IXMLDATAType DATA[int Index] = { read=Get_DATA };/* default */ }; // IXMLDATAType __interface INTERFACE_UUID("{0DBB1007-4B23-43B0-B7B1-1B05E6450425}") IXMLDATAType : public IXMLNode { public: // Eigenschaftszugriff virtual UnicodeString __fastcall Get_Wert() = 0; virtual UnicodeString __fastcall Get_bla() = 0; virtual void __fastcall Set_Wert(UnicodeString Value) = 0; virtual void __fastcall Set_bla(UnicodeString Value) = 0; // Methoden & Eigenschaften __property UnicodeString Wert = { read=Get_Wert, write=Set_Wert }; __property UnicodeString bla = { read=Get_bla, write=Set_bla }; }; // Forward-Deklarationen class TXMLContainerType; class TXMLDATAsType; class TXMLDATAType; // TXMLContainerType class TXMLContainerType : public TXMLNode, public IXMLContainerType { __IXMLNODE_IMPL__ protected: // IXMLContainerType virtual UnicodeString __fastcall Get_Allgemein(); virtual _di_IXMLDATAsType __fastcall Get_DATAs(); virtual void __fastcall Set_Allgemein(UnicodeString Value); public: virtual void __fastcall AfterConstruction(void); }; // TXMLDATAsType class TXMLDATAsType : public TXMLNodeCollection, public IXMLDATAsType { __IXMLNODECOLLECTION_IMPL__ protected: // IXMLDATAsType virtual _di_IXMLDATAType __fastcall Get_DATA(int Index); virtual _di_IXMLDATAType __fastcall Add(); virtual _di_IXMLDATAType __fastcall Insert(const int Index); public: virtual void __fastcall AfterConstruction(void); }; // TXMLDATAType class TXMLDATAType : public TXMLNode, public IXMLDATAType { __IXMLNODE_IMPL__ protected: // IXMLDATAType virtual UnicodeString __fastcall Get_Wert(); virtual UnicodeString __fastcall Get_bla(); virtual void __fastcall Set_Wert(UnicodeString Value); virtual void __fastcall Set_bla(UnicodeString Value); }; // Globale Funktionen _di_IXMLContainerType __fastcall GetContainer(_di_IXMLDocument Doc); _di_IXMLContainerType __fastcall GetContainer(TXMLDocument *Doc); _di_IXMLContainerType __fastcall LoadContainer(const UnicodeString& FileName); _di_IXMLContainerType __fastcall NewContainer(); #define TargetNamespace "" #endif
-
Franko010 schrieb:
Nur ich verzweifle ich gerade daran die geänderten Werte wieder in die XML Datei zurückschreiben.
// laden _di_IXMLDocument xmlDoc = *new TXMLDocument ("E:\\foo.xml"); _di_IXMLContainerType cont = GetContainer (xmlDoc); cont->DATAs[0].DATA[1]->Wert = "test 0001"; // speichern xmlDoc->SaveToFile ("E:\\bar.xml");
Franko010 schrieb:
bzw. gibt es was besseres als den "XML-Datenbindung Experten" oder sollte ich Informationen von einem Programm ganz anders Speicher?
Nein, so ist sicherlich der einfachste Weg.
-
Danke für die Antwort.