xml to html conversion
-
wrote on 19 Jun 2023, 06:54 last edited by
Hi ,
I wanted to convert xml to html. ( 6.5 ) using xslt file ( style sheet ) .
Can any one please give some pointers ( have checked :
Qt XML Patterns : deprecated , QTextDocumentWriter : could not find any functions which can set style sheet file. )thanks & warm regards,
~ Rudresh -
Hi ,
I wanted to convert xml to html. ( 6.5 ) using xslt file ( style sheet ) .
Can any one please give some pointers ( have checked :
Qt XML Patterns : deprecated , QTextDocumentWriter : could not find any functions which can set style sheet file. )thanks & warm regards,
~ Rudreshwrote on 20 Jun 2023, 04:59 last edited byI have tried following code , but its not as it should be.
QFile myFile("D:/Report.xml"); if (!myFile.open(QIODevice::ReadOnly | QIODevice::Text)) return -1 ; QString contents = myFile.readAll(); QTextDocument qd (contents); myFile.close(); QFile cssFile( "Report.xslt"); cssFile.open(QFile::ReadOnly); qd.setDefaultStyleSheet(cssFile.readAll()); //qd.setHtml(cssFile.readAll()); //QString html = qd.tr(cssFile.readAll()); qd.setHtml(contents); QString html = qd.toHtml(); qDebug() << html ; QFile outfile ("report.html"); if ( !outfile.open(QIODevice::WriteOnly) ) return -1 ; QTextStream out(&outfile); out << html ; outfile.close();
-
I have tried following code , but its not as it should be.
QFile myFile("D:/Report.xml"); if (!myFile.open(QIODevice::ReadOnly | QIODevice::Text)) return -1 ; QString contents = myFile.readAll(); QTextDocument qd (contents); myFile.close(); QFile cssFile( "Report.xslt"); cssFile.open(QFile::ReadOnly); qd.setDefaultStyleSheet(cssFile.readAll()); //qd.setHtml(cssFile.readAll()); //QString html = qd.tr(cssFile.readAll()); qd.setHtml(contents); QString html = qd.toHtml(); qDebug() << html ; QFile outfile ("report.html"); if ( !outfile.open(QIODevice::WriteOnly) ) return -1 ; QTextStream out(&outfile); out << html ; outfile.close();
wrote on 20 Jun 2023, 06:18 last edited by@Rudresh said in xml to html conversion:
but its not as it should be.
We don't know what that means.
I may be mistaken, but I thought @Christian-Ehrlicher replied to an identically-worded question yesterday saying that you would need a third-party library to convert XML to HTML as Qt does not offer this?
-
I have tried following code , but its not as it should be.
QFile myFile("D:/Report.xml"); if (!myFile.open(QIODevice::ReadOnly | QIODevice::Text)) return -1 ; QString contents = myFile.readAll(); QTextDocument qd (contents); myFile.close(); QFile cssFile( "Report.xslt"); cssFile.open(QFile::ReadOnly); qd.setDefaultStyleSheet(cssFile.readAll()); //qd.setHtml(cssFile.readAll()); //QString html = qd.tr(cssFile.readAll()); qd.setHtml(contents); QString html = qd.toHtml(); qDebug() << html ; QFile outfile ("report.html"); if ( !outfile.open(QIODevice::WriteOnly) ) return -1 ; QTextStream out(&outfile); out << html ; outfile.close();
wrote on 20 Jun 2023, 06:45 last edited by@Rudresh said in xml to html conversion:
QFile cssFile( "Report.xslt");
An Extensible Stylesheet Language Transformation (XSLT) is not a HTML Cascading Style Sheet (CSS). This is "not as it should be."
2/4