Results 1 to 5 of 5

Thread: Adding elements with QXmlStreamWriter

  1. #1
    Join Date
    Jul 2009
    Posts
    22
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Adding elements with QXmlStreamWriter

    So suppose we have an application that creates and writes and XML file using QXmlStreamWriter, and the XML will look like this:

    <xml>
    <element>
    <atrib>Something</atrib>
    <atrib>Something else</atrib>
    </element>
    <element>
    <atrib>Other</atrib>
    <atrib>Do not know</atrib>
    </element>
    </xlm>
    What I would neeed now is that other application opens the file and ands another <element> block so the file would look like this:

    <xml>
    <element>
    <atrib>Something</atrib>
    <atrib>Something else</atrib>
    </element>
    <element>
    <atrib>Other</atrib>
    <atrib>Do not know</atrib>
    </element>
    <element>
    <atrib>New</atrib>
    <atrib>New</atrib>
    </element>
    </xlm>
    Any guess
    class newbie: public QWidget { };

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Adding elements with QXmlStreamWriter

    Quote Originally Posted by hazardpeter View Post
    Any guess
    Em, read the docs about QXmlStreamWriter?
    Qt Code:
    1. QXmlStreamWriter stream(&output);
    2. stream.setAutoFormatting(true);
    3. stream.writeStartDocument();
    4. // write your old data.
    5. stream.writeStartElement("element");
    6. stream.writeTextElement("atrib", "New");
    7. stream.writeTextElement("atrib", "New");
    8. stream.writeEndElement();
    9. //...
    10. stream.writeEndDocument();
    To copy to clipboard, switch view to plain text mode 

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

    hazardpeter (21st August 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    22
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding elements with QXmlStreamWriter

    I see, I had thought of that. I was just hopping for another way to do this but I don't mind xD. Thanks for the information!!
    class newbie: public QWidget { };

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Adding elements with QXmlStreamWriter

    if you don't want to write all the old data yourself, you can consider using QDomDocument and adding there a new node and then simply save the whole via QDomNode::save().

  6. The following user says thank you to Lykurg for this useful post:

    hazardpeter (22nd August 2009)

  7. #5
    Join Date
    Jul 2009
    Posts
    22
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding elements with QXmlStreamWriter

    Quote Originally Posted by Lykurg View Post
    if you don't want to write all the old data yourself, you can consider using QDomDocument and adding there a new node and then simply save the whole via QDomNode::save().
    Looks good, I will look in to that, thanks
    class newbie: public QWidget { };

Similar Threads

  1. Can style sheets control rich text elements?
    By wrdieter in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2009, 13:47
  2. Adding elements to a QListView
    By Arreis in forum Newbie
    Replies: 4
    Last Post: 30th June 2009, 06:56
  3. Use QXmlStreamWriter to modify existing elements
    By rhf417 in forum Qt Programming
    Replies: 8
    Last Post: 25th June 2009, 02:23
  4. Adding JavaScript Obj to QWebView issues
    By bpetty in forum Newbie
    Replies: 2
    Last Post: 13th May 2008, 20:44
  5. Replies: 0
    Last Post: 7th April 2008, 14:27

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.