Results 1 to 6 of 6

Thread: Xml Qt4

  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 Qt4

    Is there a way of updating the text of an domelement?Or as I doing We have to create xml file again for only a text updating?

  2. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Xml Qt4

    I also got the same problem.
    I didn't find any way to update a single entry in xml file.
    now, I am reading whole xml file in some variables , updating and overwriting whole xml file.

    I am looking for, is there any direct way to update a single entry in XML file?

    hgedek, I think you have the same question?

  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 Qt4

    Yes thanks.We have the same problem.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Xml Qt4

    What about QDomDocument::replaceChild?

    Regards

  5. #5
    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 Qt4

    I tried replace child.It changed child info but created a new copy of xml file in same file too.


    QFile programFile(PARAMETER_FILE);
    programFile.open(QFile::ReadWrite);
    QDomElement element;
    XML_File xmlData;
    bool result=false;

    xmlData.read(&programFile);

    element=xmlData.domDocument.documentElement();
    if(element.tagName()=="Parameters" && element.hasChildNodes()==true)
    {
    element=element.firstChildElement();
    do
    {
    if(element.tagName().toStdString()==parameter->getName())
    {
    xmlData.ChangeParameter(parameter,element,Indexes) ;
    result=true;
    break;
    }
    else
    {
    element=element.nextSiblingElement();
    }
    }while(!element.isNull());
    }
    __________________________________________________ ________________________
    void XML_File::ChangeParameter(Parameter *parameter, QDomElement element,std::vector<unsigned int> Indexes)
    {

    QDomNodeList parameterList,elementList;
    parameterList=element.childNodes();
    unsigned int index;
    QString tagName;
    QDomElement oldTitleElement,newTitleElement,_element;
    QDomText newTitleText;
    vector<unsigned int>::iterator itr;

    for(itr=Indexes.begin();itr!=Indexes.end();itr++)
    {
    _element=parameterList.item(*itr).toElement();
    elementList=_element.childNodes();
    for(index=0;index<(unsigned int)elementList.size();index++)
    {
    oldTitleElement=elementList.item(index).toElement( );
    tagName=oldTitleElement.tagName();
    if(tagName=="Value")
    {
    newTitleElement = domDocument.createElement("Value");
    newTitleText = domDocument.createTextNode
    (QString::number(parameter->Parameters[Indexes[*itr]]->getValue()));
    newTitleElement.appendChild(newTitleText);
    _element.replaceChild(newTitleElement, oldTitleElement);
    }
    }
    }
    }


    This is my write update function.Change parameter do update.

  6. #6
    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 Qt4

    I understood that:
    If we want to change anything on XML file we have use QTextStream object.For updating an text info we have use stream again.The functions of domDocument are doing their jobs but they dont update file dynamic.We have to write the last situation using QTextStream(using save( ) ).But this time everything in XML file are copied again in it under before ones.

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.