Results 1 to 4 of 4

Thread: How to get a whole node of Xml as text

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to get a whole node of Xml as text

    For example if I have a xml like this -

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <tree path="//" message="SUCCESS">
    3. <item restype="0" resname="1myd" size="-" ver="-"
    4. lmd="2014/03/12 02:29:09" thumb="N" attrib_star="0"
    5. attrib_desc="0" share="-" capture_date="0"
    6. save_time="2014/03/12 02:29:09" chk="NA"/>
    7. <item restype="0" resname="Test333" size="-" ver="-"
    8. lmd="2014/03/11 00:53:42" thumb="N" attrib_star="0"
    9. attrib_desc="0" share="-" capture_date="0"
    10. save_time="2014/03/11 00:53:42" chk="NA"/>
    11. </tree>
    To copy to clipboard, switch view to plain text mode 


    Now I need the whole node as string like this-
    Qt Code:
    1. Output:
    2. <item restype="0" resname="Test333" size="-" ver="-" lmd="2014/03/11 00:53:42" thumb="N" attrib_star="0" attrib_desc="0" share="-" capture_date="0" save_time="2014/03/11 00:53:42" chk="NA"/>
    To copy to clipboard, switch view to plain text mode 

    What I tried was not giving me this whole thing as text.
    Qt Code:
    1. void Util::parseXml(void)
    2. {
    3. QDomDocument domDoc("myDoc");
    4. QFile file("/home/rahul/Desktop/file.xml");
    5. if(!file.open(QIODevice::ReadOnly))
    6. return;
    7. if (!domDoc.setContent(&file))
    8. {
    9. file.close();
    10. return;
    11. }
    12. file.close();
    13.  
    14. QDomNode node = domDoc.elementsByTagName("item").at(0);
    15. QDomElement elem = node.toElement();
    16. qDebug() << elem.text();
    17. }
    To copy to clipboard, switch view to plain text mode 

    Kindly help me with this. Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get a whole node of Xml as text


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

    rawfool (13th August 2014)

  4. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to get a whole node of Xml as text

    Hi anda_skoa,

    How can I get the same thing (one full node as QString) using QXmlStreamReader ?

    Thank you.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get a whole node of Xml as text

    Hmm.

    QXmlStreamReader::readNext() returns an indicator on what the stream is currently at, so it should be possible to "replay" the same things on a QXmlStreamWriter.
    E.g. when the token is StartElement, write a start element and so on.

    Cheers,
    _

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

    rawfool (19th August 2014)

Similar Threads

  1. Remove node in XML file
    By pinjul in forum Newbie
    Replies: 11
    Last Post: 7th February 2013, 11:14
  2. Designing a Node Editor (Hint: Blender Node Editor)
    By Mind Calamity in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2011, 17:22
  3. Node Shader Editor
    By AMDx64BT in forum Newbie
    Replies: 1
    Last Post: 6th December 2009, 23:30
  4. how to justfy a node is leaf node or not
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 9th April 2009, 08:40
  5. how to modify the text of node in xml docment?
    By GChen in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2009, 11:48

Tags for this Thread

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.