maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Remove element from xml file (https://talk.maemo.org/showthread.php?t=52855)

Lullen 2010-05-17 01:13

Remove element from xml file
 
How do I remove a element completly from a xml file?
Right now I use this code:
Code:

QDomNode n = root.firstChild();
    while( !n.isNull() )
    {
      QDomElement e = n.toElement();
      if( !e.isNull() )
      {
        if( e.tagName() == "exercise" )
        {
            if(name == e.attribute( "name", "" ))
            {
                e.removeAttribute("name");
                e.removeAttribute("group");
                e.removeAttribute("muscle");
                e.removeAttribute("info");
                e.removeAttribute("pic1");
                e.removeAttribute("pic2");
                e.removeAttribute("weight");
                e.removeAttribute("status");
               
            }
        }
      }
      n = n.nextSibling();
  }

The problem with this code is that it leave the end like this:
before:
<exercise status="ok" muscle="Biceps" weight="0" group="Arms" pic1="" pic2="" name="Name9" info="info"/>

after: <exercise/>

So how do I remove the tagname?

Lullen 2010-05-17 01:25

Re: Remove element from xml file
 
Solved by doing root.removeChild(n);


All times are GMT. The time now is 09:15.

vBulletin® Version 3.8.8