Important: Please read the Qt Code of Conduct -

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:, 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() );, 4);

  • Closed thread. Same discussion as "here":

Log in to reply