Qt World Summit: Register Today!

Add "<?xml version="1.0" encoding="UTF-8" standalone="no" ?>" to the beginning of a QDomDocument?

  • I'm creating a QDomDocument like:

    QDomImplementation impl;
    QDomDocumentType dtd = impl.createDocumentType("name", "bla", "ble.dtd");
    QDomDocument d = impl.createDocument(0, "name", dtd);

    After calling:
    @d.save(output, 4);@

    my XML file does not have anything like @<?xml version="1.0" encoding="UTF-8" standalone="no" ?>@ on the beginning of it. How can I add it?

    Thanks in advance

  • You can get text representation of your xml with toString(), concat it with needed xml declaration and save manually to file. AFAIK there is no builtin method for adding declaration.

  • To add the wanted line, just do :
    QDomNode node( d.createProcessingInstruction( "xml", "version="1.0"",
    "standalone="no"" ) );
    d.insertBefore( node, d.firstChild() );
    d.save(output, 4);

  • Closed thread. Same discussion as "here":http://developer.qt.nokia.com/forums/viewthread/5121/.

Log in to reply