Originally Posted by
helloworld
It would help if you explained a bit how you are parsing the document; i.e., if you are using SAX, DOM, or some other parser.
lol Sorry guy
I'm using the DOM, see:
//Checking if file exists
if(!file.exists())
{
QMessageBox::information(0,tr
("Critical Error"),tr
("The file %1 does not exist! \ nPlease try to register an account!!").
arg(arquivo
));
this->close();
}
//Checking if the file can be read and written
{
QMessageBox::information(0,tr
("Critical Error"),tr
("Failed to open file %1!").
arg(arquivo
));
file.close();
this->close();
}
//Getting the contents of the old xml
doc.setContent(&file);
file.close();
QString arquivo = "List.xml";
QFile file(arquivo);
QDomDocument doc( "List" );
//Checking if file exists
if(!file.exists())
{
QMessageBox::information(0,tr("Critical Error"),tr("The file %1 does not exist! \ nPlease try to register an account!!").arg(arquivo));
this->close();
}
//Checking if the file can be read and written
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::information(0,tr("Critical Error"),tr("Failed to open file %1!").arg(arquivo));
file.close();
this->close();
}
//Getting the contents of the old xml
doc.setContent(&file);
file.close();
To copy to clipboard, switch view to plain text mode
Thanks
Added after 36 minutes:
I changed the structure of my XML:
<list>
<client name="Google">
<dns>google.com.br</dns>
<phone>+5521XXXXXXXX</phone>
</client>
<client name="Hotmail">
<dns>hotmail.com</dns>
<phone>+5535XXXXXXXX</phone>
</client>
</list>
<list>
<client name="Google">
<dns>google.com.br</dns>
<phone>+5521XXXXXXXX</phone>
</client>
<client name="Hotmail">
<dns>hotmail.com</dns>
<phone>+5535XXXXXXXX</phone>
</client>
</list>
To copy to clipboard, switch view to plain text mode
I created a method to delete, but is not working:
{
QDomNodeList domTwm
= twmDomDocument
->elementsByTagName
( "client" );
if ( !domTwm.isEmpty() )
{
for ( uint i = 0; i < domTwm.length(); i++ )
{
if ( domTwm.at(i).toElement().attribute( "name" ) == theGroupName )
{
twmDomDocument->removeChild( domTwm.at(i) );
}
}
}
}
void Remove::RemoveGroup(QDomDocument *twmDomDocument, QString theGroupName )
{
QDomNodeList domTwm = twmDomDocument->elementsByTagName( "client" );
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
void Remove::Remover()
{
RemoveGroup(&leXml(),"Google");
}
{
//Checking if file exists
if(!file.exists())
{
QMessageBox::information(0,tr
("Critical Error"),tr
("The file %1 does not exist! \ nPlease try to register an account!!").
arg(arquivo
));
this->close();
}
//Checking if the file can be read and written
{
QMessageBox::information(0,tr
("Critical Error"),tr
("Failed to open file %1!").
arg(arquivo
));
file.close();
this->close();
}
//Getting the contents of the old xml
doc.setContent(&file);
file.close();
return doc;
}
void Remove::Remover()
{
RemoveGroup(&leXml(),"Google");
}
QDomDocument Remove::leXml()
{
QString arquivo = "List.xml";
QFile file(arquivo);
QDomDocument doc( "List" );
//Checking if file exists
if(!file.exists())
{
QMessageBox::information(0,tr("Critical Error"),tr("The file %1 does not exist! \ nPlease try to register an account!!").arg(arquivo));
this->close();
}
//Checking if the file can be read and written
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::information(0,tr("Critical Error"),tr("Failed to open file %1!").arg(arquivo));
file.close();
this->close();
}
//Getting the contents of the old xml
doc.setContent(&file);
file.close();
return doc;
}
To copy to clipboard, switch view to plain text mode
Why?
Bookmarks