[Qt-interest] xml parsing

Dan White ygor at comcast.net
Wed Oct 28 15:42:14 CET 2009


Didn't you ask this yesterday ?

“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)

----- Original Message -----
From: Hasnat Raza <hasnatzaidi at gmail.com>
To: qt-interest at trolltech.com
Sent: Wed, 28 Oct 2009 14:31:22 +0000 (UTC)
Subject: [Qt-interest] xml parsing

hi , I am trying to use xml in QT 4. I just create xml file which code is,
QDomDocument document;

QDomElement d= document.createElement("session");

d.setAttribute("name","sessiondetail");

QDomElement a = document.createElement( "title" );

a.setAttribute( "name", "SESSION_#_TITLE=" );

a.setNodeValue("Hasnat");

QDomText text = document.createTextNode( "title name" );

QDomElement b = document.createElement( "type" );

b.setAttribute( "name", "SESSION_#_TYPE =" );

QDomText text1 = document.createTextNode( "type name" );

document.appendChild( d );

d.appendChild( a );

a.appendChild( text );

d.appendChild( b );

b.appendChild( text1 );

qDebug() << a.text();

QFile file( "simple.xml" );

if( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )

{

qDebug( "Failed to open file for writing." );

return;

}

QTextStream stream( &file );

stream << document.toString();

file.close();

and its output is...

<session name="sessiondetail" >
<title name="SESSION_#_TITLE=" >title name</title>
<type name="SESSION_#_TYPE =" >type name</type>
</session>

Now i Want to save these values in another file which name lets suppose
"prac.txt"
in as format like
SESSION_#_TITLE=title name
SESSION_#_TYPE=type name

Any one please guide the way....thanks in advance
regards,
raza





More information about the Qt-interest-old mailing list