Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   XML (https://www.delphipraxis.net/46-xml/)
-   -   C++ xml parsen mit tinyxml (https://www.delphipraxis.net/179445-xml-parsen-mit-tinyxml.html)

EWeiss 7. Mär 2014 14:39

xml parsen mit tinyxml
 
Ich komme auf keinen grünen zweig. :oops:
Ich habe eine einfache XML die ich mit tinyxml parsen will mein Problem ist das ich leider nicht sehr weit komme.

XML ist angehängt!

Code:
  TiXmlDocument document(Lng->szTemp);
  document.LoadFile();   

  TiXmlHandle docHandle( &document );
  TiXmlElement* child2 = docHandle.FirstChild( "configuration" ).FirstChild( "section" ).Child( "setting", 1 ).ToElement();
  if ( child2 )
  {
      const char* sDesc = child2->GetText();
  };
GetText geht ins leere
Ich komme nicht auf die Section "SettingsDialog!
Um anschließend über while oder ne For schleife die einzelnen Values auszulesen.

kann jemand helfen..

gruss

EWeiss 8. Mär 2014 06:17

AW: xml parsen mit tinyxml
 
Noch nie jemand verwendet der eventuell helfen könnte?

gruss

EWeiss 10. Mär 2014 11:28

AW: xml parsen mit tinyxml
 
Ich habe jetzt mal eine XML erstellt die so aufgebaut ist wie eine INI-Datei.
Code:
   tinyxml2::XMLDocument doc;
   tinyxml2::XMLDeclaration * xdeclaration = doc.NewDeclaration();
  xdeclaration->SetValue("xml version=\"1.0\" encoding=\"UTF-8\"");
   
   doc.InsertFirstChild(xdeclaration);

   // first entry
   tinyxml2::XMLElement *xdocument = doc.NewElement("configuration");
  tinyxml2::XMLNode *xndocument = doc.InsertAfterChild(xdeclaration, xdocument);
   // Section
  tinyxml2::XMLElement* xeSection = doc.NewElement("section");
   xeSection->SetAttribute("name", "SettingsDialog");
   // Settings
  tinyxml2::XMLElement *xeSettings = doc.NewElement("settings");
   
   // enumerate Line count from sTextSettingDialog
   for(int i=0; i < MAX_SETTINGSDIALOG_STRINGS; i++)
   {
    // convert integer(i) to string
      std::string s = std::to_string(i);
    char const *pchar = s.c_str();

    // copy string buffer to *char
      char *buffer = new char[s.length()];
    strcpy(buffer,s.c_str());

      // using buffer for next element
      xeSettings = doc.NewElement(buffer);
      // New Settings Line
      xeSettings->SetValue("setting");
      // First Attribut for Line(i)
      xeSettings->SetAttribute("name", buffer);
      // Attribute Value for Line(i)
    xeSettings->SetAttribute("value", sTextSettingDialog[i]);
      // End Line(i)
    xeSection->InsertEndChild(xeSettings);
   }
   // close Document
  xdocument->InsertEndChild(xeSection);
   // save document file
   doc.SaveFile("English.xml");
Mein Problem ist nun wie lese ich die wieder ein.
Es gibt nicht wirklich gute Dokumentationen dazu

Wie komme ich an die Attribute ran?

Das Dokument sieht dann so aus

gruss


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:04 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz