Results 1 to 3 of 3

Thread: QXmlStreamReader help?

  1. #1
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QXmlStreamReader help?

    This is a XML file. I want to use QXmlStreamReader to read the value of href, but I don't how to know to get the its value
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE xbel>
    3. <xbel version="1.0">
    4. <folder folded="no">
    5. <FullName>Perter</FullName>
    6. <Age>38</Age>
    7. </folder>
    8. <bookmark href="http://qt.nokia.com/"/>
    9. </xbel>
    To copy to clipboard, switch view to plain text mode 
    The XML file is produced by this code after modifing the code
    http://www.java2s.com/Code/Cpp/Qt/Us...reamWriter.htm
    thanks very much
    -------------------------
    Once I have found the sulotion for that
    http://www.qtcentre.org/threads/2507...mlStreamReader
    But my current problem is update the value of href ="http://qt.nokia.com/" to href="http://www.qtcentre.org/"
    Thanks
    Last edited by nthung; 4th October 2011 at 04:18.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QXmlStreamReader help?

    Load the document into a QDomDocument, find and modify any elements you want to, then save() the QDomDocument to a QTextStream (file).

  3. The following user says thank you to ChrisW67 for this useful post:

    nthung (4th October 2011)

  4. #3
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QXmlStreamReader help?

    THis is code for updating
    Qt Code:
    1. QFile inFile("C:\\test.xml" );
    2. inFile.open( QIODevice::ReadWrite | QIODevice::Text );
    3. QDomDocument document;
    4. document.setContent( &inFile ) ;
    5.  
    6.  
    7. QDomElement documentElement = document.documentElement();
    8. QDomNodeList elements = documentElement.elementsByTagName( "TextWatermark" );
    9. QDomElement bar = elements.at(0).toElement();
    10.  
    11. if(bar.hasAttribute("FontName"))
    12. bar.setAttribute("FontName","Thanh Hung");
    13.  
    14. QFile outFile( "C:\\test.xml" );
    15. if( !outFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
    16. {
    17. qDebug( "Failed to open file for writing." );
    18. //return 0;
    19. }
    20.  
    21. QTextStream stream( &outFile );
    22. stream << document.toString();
    23.  
    24. outFile.close();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Parsing RSS 2.0 using QXmlStreamReader
    By matsukan in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2011, 11:51
  2. QXmlStreamReader
    By sophister in forum Qt Programming
    Replies: 6
    Last Post: 24th August 2011, 17:31
  3. Possilble Bug? QXmlStreamReader
    By dempsey001 in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2010, 18:46
  4. Need help with QXmlStreamReader
    By jknotzke in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2009, 09:26
  5. QXmlStreamReader and PrematureEndOfDocumentError
    By SABROG in forum Qt Programming
    Replies: 3
    Last Post: 17th July 2009, 16:53

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.