Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. XML Datei erstellen
Forum Updated to NodeBB v4.3 + New Features

XML Datei erstellen

Scheduled Pinned Locked Moved German
2 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    P_Felso
    wrote on last edited by
    #1

    Hallo Leute,

    ich möchte in einer XML Datei ein Tag suchen und dort etwas hinzufügen....

    Mein Code sieht folgendermaßen aus:

    @void handledom::writeNewTag(void)
    {

    QDomDocument doc;
    QFile file( "c://test/test3.xml" );

    if ( true == file.open(QIODevice::ReadWrite))
    {
    doc.setContent(&file);
    QDomElement root = doc.documentElement();
    if (root.tagName() == "data")
    {
    QMessageBox msgBox2;
    msgBox2.setText("soweit so gut");
    msgBox2.exec();
    }
    QDomNode n= root.firstChild();
    while(!n.isNull())
    {
    QDomElement e =n.toElement(); //convert node n to element e
    if(!e.isNull())
    {
    if(e.tagName() == "persons")
    {
    QDomElement newValueTag = doc.createElement(QString("value"));
    QDomText newValueText = doc.createTextNode(QString("1234"));
    QDomAttr newValueAttr = doc.createAttribute(QString("34ms"));
    //newValueTag.appendChild(newValueAttr);
    newValueTag.appendChild(newValueText);
    e.appendChild(newValueTag);
    QMessageBox msgBox2;
    msgBox2.setText("müsste eigentlich geklappt haben");
    msgBox2.exec();

     }
    }
    
      n = n.nextSibling();
    

    }

    }
    file.close();

    }
    @

    Mein Problem ist, dass das Programm zwar durch die append Funktionen durchläuft aber die XML Datei nicht verändert wird...
    Könnt ihr mit weiterhelfen bzw. sagen was noch falsch ist?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      du musst die Änderungen am QDomDocument auch wieder in die Datei zurückschreiben.

      file.write( doc.toByteArray(2) );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved