Hello, i need to create a function to remove a whole xml Node, in my case i need to remove the node starting with "group" tag.
This is a my xml file snip:
<?xml version='1.0' encoding='UTF-8'?>
<twm version="1.0" modify_date="2008-03-06T13:03:19" creation_date="2008-03-06T13:03:19">
<group name="test" > // remove
<option key="key" tagName="tagValue" /> // remove
</group> // remove
</twm>
<?xml version='1.0' encoding='UTF-8'?>
<twm version="1.0" modify_date="2008-03-06T13:03:19" creation_date="2008-03-06T13:03:19">
<group name="test" > // remove
<option key="key" tagName="tagValue" /> // remove
</group> // remove
</twm>
To copy to clipboard, switch view to plain text mode
and this is the code used to remove the node, but it doesn not work.
{
QDomNodeList domTwm
= twmDomDocument
->elementsByTagName
( "group" );
if ( !domTwm.isEmpty() )
{
for ( uint i = 0; i < domTwm.length(); i++ )
{
if ( domTwm.at(i).toElement().attribute( "name" ) == theGroupName )
{
twmDomDocument->removeChild( domTwm.at(i) );
}
}
}
}
bool twmXMLObject::removeGroup ( QDomDocument * twmDomDocument , QString theGroupName )
{
QDomNodeList domTwm = twmDomDocument->elementsByTagName( "group" );
if ( !domTwm.isEmpty() )
{
for ( uint i = 0; i < domTwm.length(); i++ )
{
if ( domTwm.at(i).toElement().attribute( "name" ) == theGroupName )
{
twmDomDocument->removeChild( domTwm.at(i) );
}
}
}
}
To copy to clipboard, switch view to plain text mode
After call the function removeGroup i save the xml file.
Any idea?
thx
Bookmarks