Results 1 to 5 of 5

Thread: Split QDomDocument to new QDomDocument

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Split QDomDocument to new QDomDocument

    Hi guys,

    I have an xml document and I need copy part of the content to a new xml document, following an example:

    Qt Code:
    1. <?xml encoding="utf-8" ?>
    2. <Library>
    3. <Location>
    4. <Test> <---- split here
    5. .....
    6. .....
    7. </Test>
    8. <Test2>
    9. .....
    10. .....
    11. </Test2>
    12. <Location>
    13. </Library>
    To copy to clipboard, switch view to plain text mode 

    I want to create a new document xml taking the "Test" tag as my root element. How can I do that? The next few snippets of code:

    Qt Code:
    1. ...
    2. xml.setContent(b); // It's ok, its working.
    3. QDomElement root = xml.documentElement();
    4. QDomNode node = root.firstChild();
    5. ...
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer

  2. #2
    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: Split QDomDocument to new QDomDocument

    Try with QDomNode::save().
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Split QDomDocument to new QDomDocument

    Ok, I want to put the contents of that xml in a QByteArray or QString, QDomNode::toDocument( ) thought to use, but is returning empty.

  4. #4
    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: Split QDomDocument to new QDomDocument

    Quote Originally Posted by estanisgeyer View Post
    Ok, I want to put the contents of that xml in a QByteArray or QString, QDomNode::toDocument( ) thought to use, but is returning empty.
    Because the node is not the document node. QDomNode::toDocument() docs clearly states:
    Quote Originally Posted by docs
    Converts a QDomNode into a QDomDocument. If the node is not a document the returned object will be null.
    J-P Nurmi

  5. #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: Split QDomDocument to new QDomDocument

    You can also use QDomDocument::importNode().

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.