QDomNode/Element to XML



  • Hello everyone,

    Is there any direct method to transform a QDomNode / QDomElement to its XML code? I read that there's a "save' method in QDomElement or so, but isn't there something quicker ("quicker" .. I mean without having to provide a stream which that method requires)?


  • Moderators

    First thought:

    QDomNode node;
    node.toDocument().toString();
    

    I have not checked it, though, it might not work.



  • Thank you for your answer. It seems to return an empty text. After reading through the documentation, I've found that running toDocument() on a non-document will produce a null object, so that's probably why. The "save" method works, however. I've packed the writing calls (with the stream and all) in a method and it's not that lengthy to call anymore :).


  • Moderators

    OK, nicely done :)



  • @PhantomR

    Try this,

    QDomNode node;
    node.toElement().text();


  • Moderators

    @Venkatesh-V said in QDomNode/Element to XML:

    @PhantomR

    Try this,

    QDomNode node;
    node.toElement().text();

    text() returns the element's text content. Example:

    <someTag>My text</someTag>
    

    In this case text() will return "My text". So it is not what OP wants.


Log in to reply