Results 1 to 8 of 8

Thread: Writing a XML file

  1. #1
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Writing a XML file

    Hi!
    I would like to create and write into XML file. The file should look like this:
    [HTML]
    <tcdescription>
    <platform type=something>
    <id>something</id>
    <owner>something</owner>
    <requirement>something</requirement>
    <type id=something></type>
    <style type=something></style>
    <module>something</module>
    <level id=something></level>
    <effort unit=something>something</effort>
    <startertimeout>something</startertimeout>
    <description>something </description>
    </platform>

    <platform type=something os=something>
    <activated status=something></activated>
    <timeout>something</timeout>
    <trace use_automatic=something></trace>
    <debug use_automatic=something></debug>

    <compilation type=something" default=something>
    <executable>something</executable>
    </compilation>
    <compilation type=something>
    <executable>something</executable>
    </compilation>
    </platform>

    <platform type=something os=something>
    <activated status=something></activated>
    <timeout>something</timeout>
    <trace use_automatic=something></trace>
    <debug use_automatic=something></debug>

    <compilation type=something default=something>
    <executable>something</executable>
    </compilation>
    <compilation type="release">
    <executable>something</executable>
    </compilation>
    </platform>
    </tcdescription>
    [/HTML]
    Now, I have successfully created XML file and wrote tcdescription tag with this code:
    Qt Code:
    1. QDomDocument doc("XML");
    2. QDomElement root=doc.createElement("tcdescription");
    3. doc.appendChild(root);
    To copy to clipboard, switch view to plain text mode 
    and wrote it to QTextStream and to qfile. But I don't know how to create "platform" tag. I know that I need to do with QDomelement, but I am kind of stuck, and couldn't find the solution in documentation. Any ideas how to create "platform" tag, as an element child to "tcdescription" tag?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Writing a XML file

    Qt Code:
    1. QDomDocument doc("xml");
    2. QDomElement root = doc.createElement("tcdescription");
    3. QDomElement platform = doc.createElement("platform"); // the same for next levels
    4. root.appendChild(platform); // here you attach a node to a parent
    5. doc.appendChild(root);
    To copy to clipboard, switch view to plain text mode 

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

    Djony (5th February 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Writing a XML file

    You can use the function QDomNode::appendChild.
    In example
    Qt Code:
    1. QDomElement platform;
    2. platform.setTagName("platform");
    3. platform.setAttribute("type", "something");
    4. root.appendChild(platform);
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  5. #4
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Writing a XML file

    Thank you for your answers. Now I have different problem. When I run this code:
    Qt Code:
    1. style = doc.createElement("style");//doc is QDocDocument
    2. style.setAttribute("type", "something");
    3. commonPlatform.appendChild(style); //commonPlatform is QDomEllement
    To copy to clipboard, switch view to plain text mode 

    I get this output in my xml file: [HTML]<style type="something" />[/HTML] And I would like to have "/style" closing of tag. How can I do that?

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Writing a XML file

    I don't think you can do it directly using DOM.

  7. #6
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Writing a XML file

    What is the alternative then?

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

    Default Re: Writing a XML file

    What difference does it make? A separate ending tag is only needed when there are child elements. And you'll get one in case there are.
    J-P Nurmi

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Writing a XML file

    Quote Originally Posted by Djony View Post
    What is the alternative then?
    For example you can insert ending tags using regular expressions. But I don't see why would anyone want to do it...

Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 12:47
  2. Writing to file at specific
    By safknw in forum Qt Programming
    Replies: 3
    Last Post: 1st December 2006, 12:12
  3. XML file writing
    By mbjerkne in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2006, 20:04
  4. Accessing DTD in an XML file via QtXml module?
    By jorma in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2006, 19:09
  5. Replies: 6
    Last Post: 27th February 2006, 13:47

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.