PDA

View Full Version : How to get multiple lines values in XML file..



dark1988
21st July 2008, 08:36
how to get multi line of values out of xml??

Sample xml:


<xml name="xml"/>
<xml1 name="xml1"/>
<xml2 name="xml2"/>
<xml3 name="xml3"/>

thanks in advanced..:confused:

qt code:


QDomElement roots = doc.documentElement();;
if(!roots.isNull()){
QString elementName = roots.tagName();
if(elementName.compare("xml")==0){
setxml(roots.attribute("name"));
selectedxml->setText( getxml() );
}
}

how to modify this code to get values of xml, xml1, xml2, xml3's name from xml file..
thanks..

aamer4yu
21st July 2008, 09:12
Please dont start duplicate threads. Your original thread is this. (http://www.qtcentre.org/forum/f-qt-programming-2/t-how-to-read-and-get-the-values-out-of-the-xml-14905.html)

As for you question, there are many posts related, you can search them. For further help, read about QDomDocument, QDomElement, QDomNode. You can read a xml file and set it as QDomDocument::setContent. Later u can access the nodes via QDomNode or QDomElement.

dark1988
21st July 2008, 09:22
not really understand setcontent.... Can someone explain to mi ..

patrik08
22nd July 2008, 09:24
not really understand setcontent.... Can someone explain to mi ..


You set doc.setContent your xml file after you can iterate each node name and value

if (!doc.setContent(&xmlfile,true, &errorStr, &errorLine, &errorColumn)) {

here a sample to read RSS file.....



typedef QMap<int, QStringList> RssParams;

/* read a static rss version 1/2 file and return QMap params of link title description */
RssParams ReadRssFile( QString fileplace , int limiter )
{
RssParams contingent;
QFile xmlfile( fileplace );
QString errorStr, obname, inhalt;
int errorLine, errorColumn, position;
position = 0 -1;
QDomDocument doc("RSS");
if(!xmlfile.open( QIODevice::ReadOnly ) ) {
return contingent;
}
if (!doc.setContent(&xmlfile,true, &errorStr, &errorLine, &errorColumn)) {
xmlfile.close();
return contingent;
}
QDomElement root = doc.documentElement();
QDomElement chanelbase = root.firstChildElement("channel");
QDomElement child = chanelbase.firstChildElement("item");
while (!child.isNull()) {
QString title = child.firstChildElement("title").text();
QString desc = child.firstChildElement("description").text();
QString urirss = child.firstChildElement("link").text();
if (!title.isEmpty() and !desc.isEmpty() and !urirss.isEmpty()) {
position++;
if (position < limiter) {
contingent.insert(position,QStringList() << urirss << title)<< desc);
}
}
child = child.nextSiblingElement("item");
}
xmlfile.close();
return contingent;
}