Important: Please read the Qt Code of Conduct -

QXmlStreamWriter: How to create complex xml header ?

  • Hello,

    I want to create the following complex xml header with QXmlStreamWriter:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet href="./AutoValidationRepport_HTML_Transformation.xsl" type="text/xsl" ?>
    <AutomaticValidation xmlns:xsi="" xsi:noNamespaceSchemaLocation="file:./AutoValidationRepportSchema.xsd">

    To create the first line, I could call writeStartDocument(), but for the rest I cannot find any info how to create it ?

    Could you please advise on this issue ?

    Many thannks in advance !

  • Moderators

    QByteArray data;
    QString namespaceUri = "";

    QXmlStreamWriter w(&data);
    w.setCodec("UTF-8"); //this is redundant, but that's how you set encoding
    w.writeProcessingInstruction("xml-stylesheet", "href="./AutoValidationRepport_HTML_Transformation.xsl" type="text/xsl"");

    w.writeNamespace(namespaceUri, "xsi");
    w.writeAttribute(namespaceUri, "noNamespaceSchemaLocation", "file:./AutoValidationRepportSchema.xsd");

  • thank s lot

Log in to reply