Results 1 to 3 of 3

Thread: Best way to handle XML fragments?

  1. #1
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Best way to handle XML fragments?

    I'm currently implementing a TCP API that works by sending commands as XML fragments over TCP (spec here: http://mirametrix.com/images/stories...e_API_V1.0.pdf )

    When parsing commands, I could just process the strings myself, but that seems to defeat the purpose of XML. I'd rather take advantage of Qt's XML processing capabilities. Initially I was thinking I would create a QDomElement for each received command and then use its functions to get the command type and attributes. However I can't find a way to create a QDomElement from a string.

    Is there an easy way to use Qt's XML classes when the data is just XML fragments instead of a complete document? QXmlStreamReader seems promising but I think it wants full documents, and it might be overkill for the purposes of reading single elements...

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best way to handle XML fragments?

    QDomDocument::setContentJust use this function to see if you have got valid XML.
    Something like -
    Qt Code:
    1. if(doc.setContent(buffer))
    2. {
    3. // you got valid xml in doc
    4. buffer = buffer.remove(doc.string()); // remove the valid xml from buffer
    5. }
    6. else
    7. // continue or wait for next data
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Best way to handle XML fragments? [SOLVED]

    I ended up using QXmlStreamReader/Writer. I thought I would need complete XML docs, but it works just fine on fragments, as long as those fragments are valid XML.

Similar Threads

  1. handle exception in Qt
    By Qt Coder in forum Qt Programming
    Replies: 4
    Last Post: 6th April 2009, 06:05
  2. Can Qt handle pdf documents???
    By webquinty in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd March 2009, 15:16
  3. QUrl.toLocalFile() and fragments.
    By amicitas in forum Qt Programming
    Replies: 0
    Last Post: 7th October 2008, 09:27
  4. How to Handle new Qt?
    By ashukla in forum General Programming
    Replies: 3
    Last Post: 3rd March 2008, 11:50
  5. QDesktopServices::openUrl and HTML fragments
    By roro in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2007, 17:31

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.