使用<pre>标签,里面的xml被转义

本文介绍了在发现Apache Commons Lang3部分功能被标记为过时后,寻找并使用其替代品Apache Commons Text的过程。文章详细解释了如何在项目中引入新的依赖,并探讨了这一变化对代码库的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官网上面有介绍:

如果在后端可以使用:

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>

 正当兴致冲冲去使用时发现@Deprecated 意味着使用就要被标记成下划线,太难看。既然官方已经弃用了找到替代品:

 <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.8</version>
        </dependency>

 

 

<html><head><meta http-equiv="Content-Type" content="text/html; charset= =iso-8859-1"> <title>Trioptics Certificate</title> <link type="text/css" rel="stylesheet" href="certificate.css"></link> <base href="file:///C:/Program%20Files%20(x86)/TRIOPTICS%20GmbH/MTF-LAB%2= 05/Certificates/"></base></head> <body id="IBodyCert" class="CBodyCert"> <!-- open certificate table --> <table align="left" id="ITableCert" class="CTableCert"> <!-- Header --> <tbody><tr id="ITRCompany" class="CTRHeader"> <td id="ITDCompany" class="CTDHeader"> <div id="IDivCompany" class="CDivHeader">ImageMaster - Certificate</div> </td> <td id="ITDLogo" class="CTDHeader"> <img src="./img/Trioptics-Logo-250x65.png" id="ITDLogo" class="CTDHea= der"> </td> </tr> <tr id="ITDSlogan" class="CTRHeader"> <td colspan="2" id="ITDSlogan" class="CTDHeader"> </td> </tr> <tr> <td colspan="2"> <pre>Company : ****** Operator : ****** Time/Date : 13:30:33 June 12, 2025 Sample ID : ****** Measure Program : MTF vs. Field Temperature : 20°C Measured with : <a href="http://www.trioptics.com/">TRIOPTICS</a> - MT= F-LAB - Vers. 5.16.1 Instrument S/N : 09-113-0519 Comments : SN215U0540 </pre> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> <hr> <b>Measurement Parameter: MTF vs. Image Height</b> <pre>Setup Type : Object Infinite / Image Finite EFL (Collimator): 50 mm Wavelength : 940 nm (NIR) EFL (Sample) : 1.5550 mm F-Number : 2.0000 Object Angle : -0.0198 ° Focus Position : 85.8471 Sample Azimuth : 0.0 ° </pre></td> </tr> <tr> <td colspan="2"> <hr> <b>Measurement Graph: MTF vs. Image Height</b> <br><br> <right> <img src="Chart12.png"> </right> </td> </tr> <tr> <td colspan="2"> <hr> <b>Measurement Table: MTF vs. Image Height</b> <br><br> <!-- open measurement table --> <table cellspacing="0" align="left" id="ITableDataItems" class="CTa= bleDataItems"> <!-- begin table caption --> <tbody><tr id="ITRDataCaption" class="CTRDataCaption"> <td id="ITDCaptionBlank" class="CTDCaptionBlank"></td> <td align="center" colspan="5" id="ITDDataCaption" class="CTDDataCa= ption">Image Height (mm)</td> </tr> <tr id="ITRDataCaption" class="CTRDataCaption"> <td id="ITDDataCaption" class="CTDDataCaption">MTF</td> <td id="ITDDataCaption" class="CTDDataCaption">0.42800</td> <td id="ITDDataCaption" class="CTDDataCaption">0.29960</td> <td id="ITDDataCaption" class="CTDDataCaption">-0.00114</td> <td id="ITDDataCaption" class="CTDDataCaption">-0.29960</td> <td id="ITDDataCaption" class="CTDDataCaption">-0.42800</td> <td id="ITDDataCaption" class="CTDDataCaption">Legend</td> </tr> <!-- end table caption --> <!-- begin measurement data --> <tr id="ITRDataItem" class="CTRDataItem"> <td id="ITDEven" class="CTDDataItem">Tan 100(lp/mm)</td> <td id="ITDEven" class="CTDDataItem">0.599</td> <td id="ITDEven" class="CTDDataItem">0.677</td> <td id="ITDEven" class="CTDDataItem">0.668</td> <td id="ITDEven" class="CTDDataItem">0.703</td> <td id="ITDEven" class="CTDDataItem">0.645</td> <td colspan="1" id="ITDLegend" class="CTDLegend"><font color="ff000= 0">— — —</font></td> </tr> <tr id="ITRDataItem" class="CTRDataItem"> <td id="ITDEven" class="CTDDataItem">Sag 100(lp/mm)</td> <td id="ITDEven" class="CTDDataItem">0.558</td> <td id="ITDEven" class="CTDDataItem">0.659</td> <td id="ITDEven" class="CTDDataItem">0.673</td> <td id="ITDEven" class="CTDDataItem">0.688</td> <td id="ITDEven" class="CTDDataItem">0.642</td> <td colspan="1" id="ITDLegend" class="CTDLegend"><font color="ff000= 0">————</font></td> </tr> <!-- end measurement data --> <!-- close measurement table --> </tbody></table><br clear="all"> </td> </tr> <tr> <td colspan="2"> <hr> <b>Measurement Parameter: MTF vs. Object Angle</b> <pre>Setup Type : Object Infinite / Image Finite EFL (Collimator): 50 mm Wavelength : 940 nm (NIR) EFL (Sample) : 1.5550 mm F-Number : 2.0000 Object Angle : -0.0198 ° Focus Position : 85.8471 Sample Azimuth : 0.0 ° </pre></td> </tr> <tr> <td colspan="2"> <hr> <b>Measurement Graph: MTF vs. Object Angle</b> <br><br> <right> <img src="Chart11.png"> </right> </td> </tr> <tr> <td colspan="2"> <hr> <b>Measurement Table: MTF vs. Object Angle</b> <br><br> <!-- open measurement table --> <table cellspacing="0" align="left" id="ITableDataItems" class="CTa= bleDataItems"> <!-- begin table caption --> <tbody><tr id="ITRDataCaption" class="CTRDataCaption"> <td id="ITDCaptionBlank" class="CTDCaptionBlank"></td> <td align="center" colspan="5" id="ITDDataCaption" class="CTDDataCa= ption">Object Angle (?</td> </tr> <tr id="ITRDataCaption" class="CTRDataCaption"> <td id="ITDDataCaption" class="CTDDataCaption">MTF</td> <td id="ITDDataCaption" class="CTDDataCaption">-15.33590</td> <td id="ITDDataCaption" class="CTDDataCaption">-10.72937</td> <td id="ITDDataCaption" class="CTDDataCaption">0.00072</td> <td id="ITDDataCaption" class="CTDDataCaption">10.77662</td> <td id="ITDDataCaption" class="CTDDataCaption">15.40352</td> <td id="ITDDataCaption" class="CTDDataCaption">Legend</td> </tr> <!-- end table caption --> <!-- begin measurement data --> <tr id="ITRDataItem" class="CTRDataItem"> <td id="ITDEven" class="CTDDataItem">Tan 100(lp/mm)</td> <td id="ITDEven" class="CTDDataItem">0.599</td> <td id="ITDEven" class="CTDDataItem">0.677</td> <td id="ITDEven" class="CTDDataItem">0.668</td> <td id="ITDEven" class="CTDDataItem">0.703</td> <td id="ITDEven" class="CTDDataItem">0.645</td> <td colspan="1" id="ITDLegend" class="CTDLegend"><font color="ff000= 0">— — —</font></td> </tr> <tr id="ITRDataItem" class="CTRDataItem"> <td id="ITDEven" class="CTDDataItem">Sag 100(lp/mm)</td> <td id="ITDEven" class="CTDDataItem">0.558</td> <td id="ITDEven" class="CTDDataItem">0.659</td> <td id="ITDEven" class="CTDDataItem">0.673</td> <td id="ITDEven" class="CTDDataItem">0.688</td> <td id="ITDEven" class="CTDDataItem">0.642</td> <td colspan="1" id="ITDLegend" class="CTDLegend"><font color="ff000= 0">————</font></td> </tr> <!-- end measurement data --> <!-- close measurement table --> </tbody></table><br clear="all"> </td> </tr> <!-- close certificate table --> </tbody></table> </body></html> 为啥这个内容调用QDomDocument的setContent会失败
06-28
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><meta content="IE=5.0000" = http-equiv="X-UA-Compatible"/> <TITLE>Trioptics Certificate</TITLE> <meta http-equiv="Content-Type" content="text/html; = charset=windows-1252"/><link href="file:///C:/Program%20Files/Trioptics%20GmbH/MTF-LAB%205/Certifica= tes/certificate.css" rel="stylesheet" type="text/css"/> <meta name="GENERATOR" content="MSHTML 11.00.9600.18538"/></HEAD> <BODY class="CBodyCert" id="IBodyCert"><!-- open certificate table = --> <TABLE align="left" class="CTableCert" id="ITableCert"><!-- Header = --> <TBODY> <TR class="CTRHeader" id="ITRCompany"> <TD class="CTDHeader" id="ITDCompany"> <DIV class="CDivHeader" id="IDivCompany">ImageMaster - Certificate</DIV></TD> <TD class="CTDHeader" id="ITDLogo"><img class="CTDHeader" = id="ITDLogo" = src="file:///C:/Program%20Files/Trioptics%20GmbH/MTF-LAB%205/Certificat= es/img/Trioptics-Logo-250x65.png"/> </TD></TR> <TR class="CTRHeader" id="ITDSlogan"> <TD class="CTDHeader" id="ITDSlogan" colspan="2"></TD></TR> <TR> <TD colspan="2"> <PRE>Company : Sunex = Operator : TH = Time/Date : 20:29:14 June 14, 2025 = Sample ID : 0 = Measure Program : 3D Tilt Corrected Through Focus = Temperature : 20°C = Measured with : <A href="http://www.trioptics.com/">TRIOPTICS</A> - = MTF-LAB - Vers. 5.13.2 = Instrument S/N : 09-113-0259 = Comments : AMT5 = </PRE></TD></TR> <TR>// 修复HTML文档使其符合XML规范: QString TriopticsParser::preprocessHtmlForXml(const QString & html) { QString result = html; // 1. 修复字符集声明 result.replace("charset=\n=iso-8859-1", "charset=\"iso-8859-1\""); // 2. 转义URL中的&符号 result.replace(QRegularExpression("href=\"([^\"]*?)(?<!&|<|>|&apos;|")&([^\"]*?)\""), "href=\"\\1&\\2\""); // 3. 修复自闭合标签 QStringList selfClosingTags = { "img", "br", "hr", "meta", "link" }; for (const QString& tag : selfClosingTags) { // 处理有属性的标签 result.replace(QRegularExpression(QString("<%1\\b([^>]*)>").arg(tag), QRegularExpression::CaseInsensitiveOption), QString("<%1\\1/>").arg(tag)); // 处理没有属性的标签 result.replace(QRegularExpression(QString("<%1\\s*>").arg(tag), QRegularExpression::CaseInsensitiveOption), QString("<%1/>").arg(tag)); } // 4. 移除无效的</link>结束标签 result.replace("</link>", ""); // 5. 添加XML声明 if (!result.contains("<?xml")) { result.prepend("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); } return result; }
最新发布
07-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码海无涯苦做舟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值