This code may help u............
	
	- #ifndef CONTACT_H 
- #define CONTACT_H 
-   
- #include<QtCore/QString> 
-   
-   
- class Contact 
- { 
- public: 
-   
-   
- }; 
-   
- #endif 
        #ifndef CONTACT_H
#define CONTACT_H
#include<QtCore/QString>
class QDomElement;
class QDomDocument;
class QString;
class Contact
{
public:
    QString name,eMail,phone;
		
    Contact( QString iName = "", QString iPhone = "", QString iEMail = "" );
    Contact( const QDomElement &e );
};
#endif
To copy to clipboard, switch view to plain text mode 
  
	
	- //contact.cpp 
-   
- #include"contact.h" 
-   
- #include <qapplication.h> 
- #include <QtXml/QDomNode> 
-   
- #include <QtCore/QDir> 
- #include <QtCore/QFile> 
- #include <QtCore/QIODevice> 
- #include <QDebug> 
- #include <QtXml/QDomDocument> 
-   
-   
-   
-   
- { 
- 	name = iName; 
- 	phone = iPhone; 
- 	eMail = iEMail; 
- } 
-   
- { 
-   
-    cn.setAttribute( "NAME", c.name ); 
-    cn.setAttribute( "PHONE", c.phone ); 
-    cn.setAttribute( "EMAIL", c.eMail ); 
-   
-    return cn; 
- } 
-   
-   
- int main( int argc, char **argv ) 
- { 
-   
-   doc.appendChild(root); 
-   
-   Contact c; 
-   
-   c.name = "AAAA"; 
-   c.eMail = "AAAA@gmail.com"; 
-   c.phone = "+91-32233223"; 
-   
-   root.appendChild(ContactToNode(doc,c)); 
-   
-   return -1; 
-   
-   ts << doc.toString(); 
-   
-   file.close(); 
-   
-   
-   c.name = "BBBBB"; 
-   c.eMail = "BBBB@gmail.com"; 
-   c.phone = "+91-3233443440"; 
-   
-   root.appendChild( ContactToNode( doc, c ) ); 
-   return -1; 
-   
-   
-   ts << doc.toString(); 
-   
-   c.name = "CCCCC"; 
-   c.eMail = "maassy@gmail.com"; 
-   c.phone = "+91-98232388"; 
-   
-   root.appendChild( ContactToNode( doc, c ) ); 
-   return -1; 
-   
-   
-   ts << doc.toString(); 
-   
-  file.close(); 
-   
-   return -1; 
- if( !doc.setContent( &file ) ) 
- { 
-   file.close(); 
-   return -2; 
- } 
-  root = doc.documentElement(); 
- if( root.tagName() != "adbook" ) 
-   return -3; 
- while( !n.isNull() ) 
- { 
-   if( !e.isNull() ) 
-   { 
-     if( e.tagName() == "contact" ) 
-     { 
-       Contact c ; 
-   
-       c.name = e.attribute( "NAME","" ); 
-       c.phone = e.attribute( "PHONE","" ); 
-       c.eMail = e.attribute( "EMAIL","" ); 
-   
-       qDebug()<<c.name; 
-       qDebug()<<c.phone; 
-       qDebug()<<c.eMail; 
-   
-     } 
-   } 
-   
-   n = n.nextSibling(); 
- } 
-   return 0; 
- } 
        //contact.cpp
#include"contact.h"
#include <qapplication.h>
#include <QtXml/QDomNode>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QIODevice>
#include <QDebug>
#include <QtXml/QDomDocument>
Contact::Contact( QString iName, QString iPhone, QString iEMail )
{
	name = iName;
	phone = iPhone;
	eMail = iEMail;
}
QDomElement ContactToNode(QDomDocument &d, const Contact &c )
{
   QDomElement cn = d.createElement( "contact" );
   cn.setAttribute( "NAME", c.name );
   cn.setAttribute( "PHONE", c.phone );
   cn.setAttribute( "EMAIL", c.eMail );
   return cn;
}
int main( int argc, char **argv )
{
  QApplication a( argc, argv );
  QDomDocument doc("AdBookML");
  QDomElement root = doc.createElement( "adbook" );
  doc.appendChild(root);
  Contact c;
  c.name = "AAAA";
  c.eMail = "AAAA@gmail.com";
  c.phone = "+91-32233223";
  root.appendChild(ContactToNode(doc,c));
 QFile file("test.xml");
  if( !file.open( QIODevice::WriteOnly ) )
  return -1;
  QTextStream ts( &file );
  ts << doc.toString();
  file.close();
  c.name = "BBBBB";
  c.eMail = "BBBB@gmail.com";
  c.phone = "+91-3233443440";
  root.appendChild( ContactToNode( doc, c ) );
if( !file.open( QIODevice::WriteOnly  ) )
  return -1;
  
  ts << doc.toString();
  c.name = "CCCCC";
  c.eMail = "maassy@gmail.com";
  c.phone = "+91-98232388";
  root.appendChild( ContactToNode( doc, c ) );
if( !file.open( QIODevice::WriteOnly ) )
  return -1;
  
  ts << doc.toString();
 file.close();
if( !file.open(QIODevice::ReadOnly ))
  return -1;
if( !doc.setContent( &file ) )
{
  file.close();
  return -2;
}
 root = doc.documentElement();
if( root.tagName() != "adbook" )
  return -3;
QDomNode n = root.firstChild();
while( !n.isNull() )
{
  QDomElement e = n.toElement();
  if( !e.isNull() )
  {
    if( e.tagName() == "contact" )
    {
      Contact c ;
      c.name = e.attribute( "NAME","" );
      c.phone = e.attribute( "PHONE","" );
      c.eMail = e.attribute( "EMAIL","" );
      qDebug()<<c.name;
      qDebug()<<c.phone;
      qDebug()<<c.eMail;
     
    }
  }
  n = n.nextSibling();
}
  return 0;
}
To copy to clipboard, switch view to plain text mode 
  Thanks
				
			
Bookmarks