Results 1 to 3 of 3

Thread: Create fragments of XML while parsing XML document

  1. #1
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Create fragments of XML while parsing XML document

    I have a XMLDocument which I parse. At certain points I wish to extract elements/nodes as fragments of XML (QString or UTF-8 encoded QByteArray).

    toDocument and toDocumentFragment returns nothing.

    I can do this with XPath but this is not what I want. What am I missing? How do I achieve this in Qt?

    Simplified code:
    Qt Code:
    1. if (doc.setContent(data))
    2. {
    3. QDomElement elementEnvelope = doc.firstChildElement();
    4. QDomElement elementBody = elementEnvelope.firstChildElement();
    5. QDomElement elementMethod = elementBody.firstChildElement();
    6. QDomElement elementParameter = elementMethod.firstChildElement("blah");
    7. }
    To copy to clipboard, switch view to plain text mode 

    It's the elementParameter and everything from that point, I wish to extract as XML.

    Thanks in advance!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Create fragments of XML while parsing XML document

    Use this void QDomElement::save(QTextStream&, int) const;
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Create fragments of XML while parsing XML document

    Doh, I had tried the save function everything else but the element itself Thanks for the help!

Similar Threads

  1. Replies: 2
    Last Post: 13th July 2014, 04:09
  2. Best way to handle XML fragments?
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2010, 19:21
  3. QUrl.toLocalFile() and fragments.
    By amicitas in forum Qt Programming
    Replies: 0
    Last Post: 7th October 2008, 10:27
  4. QDesktopServices::openUrl and HTML fragments
    By roro in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2007, 18: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.