Results 1 to 4 of 4

Thread: How to get multiple lines values in XML file..

  1. #1
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to get multiple lines values in XML file..

    how to get multi line of values out of xml??

    Sample xml:

    Qt Code:
    1. <xml name="xml"/>
    2. <xml1 name="xml1"/>
    3. <xml2 name="xml2"/>
    4. <xml3 name="xml3"/>
    To copy to clipboard, switch view to plain text mode 
    thanks in advanced..

    qt code:

    Qt Code:
    1. QDomElement roots = doc.documentElement();;
    2. if(!roots.isNull()){
    3. QString elementName = roots.tagName();
    4. if(elementName.compare("xml")==0){
    5. setxml(roots.attribute("name"));
    6. selectedxml->setText( getxml() );
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    how to modify this code to get values of xml, xml1, xml2, xml3's name from xml file..
    thanks..
    Last edited by jpn; 21st July 2008 at 13:25. Reason: missing [code] tags

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get multiple lines values in XML file..

    Please dont start duplicate threads. Your original thread is this.

    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.

  3. #3
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get multiple lines values in XML file..

    not really understand setcontent.... Can someone explain to mi ..

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get multiple lines values in XML file..

    Quote Originally Posted by dark1988 View Post
    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.....

    Qt Code:
    1. typedef QMap<int, QStringList> RssParams;
    2.  
    3. /* read a static rss version 1/2 file and return QMap params of link title description */
    4. RssParams ReadRssFile( QString fileplace , int limiter )
    5. {
    6. RssParams contingent;
    7. QFile xmlfile( fileplace );
    8. QString errorStr, obname, inhalt;
    9. int errorLine, errorColumn, position;
    10. position = 0 -1;
    11. QDomDocument doc("RSS");
    12. if(!xmlfile.open( QIODevice::ReadOnly ) ) {
    13. return contingent;
    14. }
    15. if (!doc.setContent(&xmlfile,true, &errorStr, &errorLine, &errorColumn)) {
    16. xmlfile.close();
    17. return contingent;
    18. }
    19. QDomElement root = doc.documentElement();
    20. QDomElement chanelbase = root.firstChildElement("channel");
    21. QDomElement child = chanelbase.firstChildElement("item");
    22. while (!child.isNull()) {
    23. QString title = child.firstChildElement("title").text();
    24. QString desc = child.firstChildElement("description").text();
    25. QString urirss = child.firstChildElement("link").text();
    26. if (!title.isEmpty() and !desc.isEmpty() and !urirss.isEmpty()) {
    27. position++;
    28. if (position < limiter) {
    29. contingent.insert(position,QStringList() << urirss << title)<< desc);
    30. }
    31. }
    32. child = child.nextSiblingElement("item");
    33. }
    34. xmlfile.close();
    35. return contingent;
    36. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 02:20
  2. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 07:51
  3. reading from a file
    By mickey in forum General Programming
    Replies: 32
    Last Post: 19th July 2007, 02:04
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  5. Replies: 13
    Last Post: 21st June 2006, 22:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.