Reply
Thread Tools
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#1
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?
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#2
Solved by doing root.removeChild(n);
 

The Following User Says Thank You to Lullen For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 21:01.