Results 1 to 3 of 3

Thread: XML -read-write

  1. #1
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default XML -read-write

    I used read(QIODevice *device) and write(QIODevice *device) functions for reading and writing.I could read infos from xml.I wanted to change only a text.
    <Name>xxxxx</Name> to <Name> yyyyy </Name>
    But I couldnt find the function.(Ex:setText() or setValue())
    In examples I saw that everything is created again.But This is too long for only a text.
    Is there a way for writing XML?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: XML -read-write

    See QtXml module.
    J-P Nurmi

  3. #3
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: XML -read-write

    I read.These are my write functions.I can change value but not in xml file.I cant write new value to xml file.Will I change all file?

    Qt Code:
    1. bool Data::WriteParameter(Parameter *parameter, std::vector<unsigned int> Indexes)
    2. {
    3.  
    4. QFile programFile(PARAMETER_FILE);//xml verildi
    5. QDomElement element;//xml üzerinde işlem yapacak
    6. XML_File xmlData;//bu file bu sinif içinde açılacak
    7. bool result=false;
    8.  
    9. xmlData.read(&programFile);
    10. element=xmlData.domDocument.documentElement();
    11. if(element.tagName()=="Parameters" && element.hasChildNodes()==true)
    12. {
    13. element=element.firstChildElement();
    14. do
    15. {
    16. if(element.tagName().toStdString()==parameter->getName())
    17. {
    18. ChangeParameter(parameter,element,Indexes);
    19. result=true;
    20. break;
    21. }
    22. else
    23. {
    24. element=element.nextSiblingElement();
    25. }
    26. }while(!element.isNull());
    27.  
    28. xmlData.write(&programFile);
    29. }
    30. return result;
    31.  
    32. }
    33.  
    34. void Data::ChangeParameter(Parameter *parameter, QDomElement element,std::vector<unsigned int> Indexes)
    35. {
    36. unsigned int index;
    37. QString tagName;
    38. QDomElement _element;QDomCharacterData dataLn;
    39. QDomText elementText;
    40. QDomNodeList parameterList,elementList;
    41. parameterList=element.childNodes();
    42. vector<unsigned int>::iterator itr;
    43. for(itr=Indexes.begin();itr!=Indexes.end();itr++)
    44. {
    45. elementList=parameterList.item(*itr).toElement().childNodes();
    46. for(index=0;index<(unsigned int)elementList.size();index++)
    47. {
    48. _element=elementList.item(index).toElement();
    49. tagName=_element.tagName();
    50. if(tagName=="Value")
    51. {
    52. elementText=_element.childNodes().item(0).toText();
    53. dataLn=elementText.toCharacterData();
    54. //elementText.setNodeValue(QString::number(parameter->Parameters[*itr]->getValue()));
    55. dataLn.replaceData(0,QString::number(parameter->Parameters[*itr]->getValue()).length(),
    56. QString::number(parameter->Parameters[*itr]->getValue()));
    57. }
    58. }
    59. }
    60. }
    61.  
    62. bool XML_File::write(QIODevice *device)
    63. {
    64.  
    65. const int IndentSize = 4;
    66.  
    67. QTextStream out(device);
    68. domDocument.save(out, IndentSize);
    69. return true;
    70. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 4th September 2007 at 15:53. Reason: missing [code] tags

Similar Threads

  1. How can I Read Write Excel File
    By xingshaoyong in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2011, 21:16
  2. Read \Write Excel File using Qt
    By xingshaoyong in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 23:07
  3. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 07:48
  4. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 15:12
  5. QIODevice read()
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 01:29

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.