0

嗨,我在将 html 转换为 PDF 时遇到该错误这是我的 html:

String html = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<html>"
            + "<head><style>"
            + "@font-face { "
            + "  src: url(arial.ttf); "
            + "  -fs-pdf-font-embed: embed; "
            + "  -fs-pdf-font-encoding: Identity-H;}"
            + "html *"
            + "{font-size: 11px;"
            + " font-family: Arial;}"
            + "</style></head>"
            + "<body>"
            + "<div id=\"logo\" class=\"media\" data-src=\"gsis.PNG\" style=\"width: 90px; height: 90px\" ></div>"
            + "<p style=\"text-align: center; line-height: 90%; \">Statement of Members Account</p>"
            + "<p style=\"text-align: center; line-height: 90%; \">Premium and Loan Account Balances Index</p>"
            + "<p style=\"text-align: center; line-height: 90%; \">As of "+ dateFormat.format(date) +"</p>"
            + "<br></br>"
            + "<table style=\"width: 100%;\">"
            + var1
            + "</table>"
            + "<br></br>"
            + "<hr></hr>"
            + "<br></br>"
            + "<p>This is the summary of your premium and loan account balances on record with GSIS as of "+ dateFormat.format(date) +"."
            + " To view a more updated summary and detailed account balances, you can go to "
            + "<span style=\"color: #0000ff; font-style: italic; text-decoration: underline;\">www.gsis.gov.ph</span> and log-on to eGSISMO."
            + "</p>"
            + "<p>In case of any discrepancy, please coordinate with your Personnel/Accounting Office to facilitate reconciliation of your record"
            + "and accounts with GSIS.</p>"
            + "<br></br>"
            + "I. PREMIUM ACCOUNT"
            + "<br></br>"
            + "<table border=\"1\" style=\"width: 100%; \">"
            + "<tr>"
            + "<td>Policy Type</td>"
            + "<td>Policy Number/Insurance Account</td>"
            + "<td>Due</td>"
            + "<td>Interest</td>"
            + "<td>Total</td>"
            + "</tr>"
            + var2
            + "</table>"
            + "<br></br>"
            + "<br></br>"
            + "II. LOAN ACCOUNT"
            + "<br></br>"
            + "<table border=\"1\" style=\"width: 100%; \">"
            + "<tr>"
            + "<td>Loan Type</td>"
            + "<td>Contract Account</td>"
            + "<td>Date Loan Granted</td>"
            + "<td>Gross Loan Amount</td>"
            + "<td>Monthly Amort</td>"
            + "<td>Total Repayment</td>"
            + "<td>Principal Balance</td>"
            + "<td>Interest/Surcharge</td>"
            + "<td>Outstanding Balance</td>"
            + "</tr>"
            + var3
            + "<br></br>"
            + "</table>"
            + "<br></br>"
            + "<br></br>"
            + "III. Period with Premium Payment (PPP)"
            + "<table cellpadding=\"10\" border=\"1\" style=\"width: 100%; \">"
            + var4
            + "</table>"
            + "<br></br>"
            + "<br></br>"
            + "LEGEND:"
            + "<br></br>"
            + "<p>A. Total Length of Service is the total number of years, months, days you are in government service.</p>"
            + "<p>B. Total Leave of Absence WITHOUT Pay (LWOP) is the period of time where no actual service was rendered "
            + "and paid. As such, premium payment for said period of time is not required. In which case, the period is not "
            + "considered in the computation of total length of service.</p>"
            + "<p>C. Actual Length of Service is the Total Length of Service less Total Leave of Absence WITHOUT Pay</p>"
            + "<p>D. Actual Length of Service WITH Posted Premium Payment (PPP) is the number of years in service"
            + " wherein correct premium payments have been paid and posted.</p>"
            + "<p>E. Actual Length of Service WITHOUT Posted Premium Payment (PPP) is the number of years in service "
            + "that do not have premium payments. This is subject to reconciliation with the member and agency record.</p>"
            + "<p>F. Equivalent Salary Based on Posted Premium Payment is the salary which had paid premium payment. This "
            + "salary will be used in the computation of gross loan amount.</p>"
            + "</body>"
            + "</html>";

是的,更多的措辞。我在整个 html 代码中找不到任何 & 。那么这个错误来自哪里?:

 ERROR:  'The entity name must immediately follow the '&' in the entity reference.'
org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.

变量1

 String var1 = "<tr>"
            + "<td style=\"align: left; width: 80px; \">Name:</td>"
            + "<td colspan=\"4\" style=\"width: 60%;\">" + fullName + "</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"align: left; width: 80px; \">Address:</td>"
            + "<td colspan=\"4\" style=\"width: 60%;\">" + address + "</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"align: left; width: 80px; \">Agency:</td>"
            + "<td colspan=\"4\" style=\"width: 60%;\">" + agencyName + "</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"align: left; width: 80px; \"></td>"
            + "<td colspan=\"4\" style=\"width: 60%;\">" + agencyAddress + "</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"align: left; width: 80px; \">Date of Birth:</td>"
            + "<td style=\"width: 60%;\">" + dob + "</td>"
            + "<td style=\"align: left;\">CRN:</td>"
            + "<td>" + crn + "</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"align: left; width: 80px; \">BP No:</td>"
            + "<td style=\"width: 60%;\">" + bp + "</td>"
            + "<td style=\"align: left;\">ID No:</td>"
            + "<td>" + id + "</td>"
            + "</tr>";

变量2

String var2 = "<tr>"
            + "<td>" + policyType + "</td>"
            + "<td>" + policyNumber + "</td>"
            + "<td>" + personalShare + "</td>"
            + "<td>" + psLifeInterest + "</td>"
            + "<td>" + psTotal + "</td>"
            + "</tr>";

变量3

String var3 = null;

        var3 += "<tr>"
                + "<td>" + loanType + "</td>"
                + "<td>" + contract + "</td>"
                + "<td>" + dateLoanGrancted + "</td>"
                + "<td>" + grossAmt + "</td>"
                + "<td>" + totAmortAmt + "</td>"
                + "<td>" + totRepaymentAmt + "</td>"
                + "<td>" + obPrincipalAmt + "</td>"
                + "<td>" + intSurAmt + "</td>"
                + "<td>" + obTotAmt + "</td>"
                + "</tr>";

var4

String var4 = "<tr>"
            + "<td style=\"width:10px;\">A</td>"
            + "<td style=\"width:60%;\">Total Length of Service (TLS) in Years</td>"
            + "<td>"+tls+"</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"width:10px;\">B</td>"
            + "<td style=\"width:60%;\">Total Leave Of Absence Without Pay (LWOP) in Years</td>"
            + "<td>"+lwop+"</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"width:10px;\">C</td>"
            + "<td style=\"width:60%;\">Actual Length of Service</td>"
            + "<td>"+als+"</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"width:10px;\">D</td>"
            + "<td style=\"width:60%;\">Actual Length of Period WITH Premium Payment (PPP)</td>"
            + "<td>"+rcs+"</td>"
            + "</tr>"
            + "<tr>"
            + "<td style=\"width:10px;\">E</td>"
            + "<td style=\"width:60%;\">Actual Length of Period WITHOUT Premium Payment</td>"
            + "<td>"+rcso+"</td>"                
            + "</tr>";

我还调查了我得到的数据,没有任何形式的 & 符号。对此感到很困惑。如果有任何&符号(&),我也会搜索我的代码,但我什么也没找到。

这是 SQL 数据

PARTNER,NAME_FIRST,NAMEMIDDLE,NAME_LAST,ZZSUFFIX,FULLNAME,AGENCY_NAME,AGENCY_ADDRESS,AGENCY

_BP_NUMBER,BDAY,BIRTHDATE,IDNO,CRN,POLICY_TYPE,MEM_ADDRESS,TOTAL_LENGTH_OF_SERVICE,INSOBJECT,POLICY_NUMBER,PERSONAL_SHARE,GOV_SHARE,EC_LIFE,PS_LIFE_INTEREST,GS_LIFE_INTEREST,PS_RET_INTEREST,GS_RET_INTEREST,EC_INTEREST,PROD_TYPE,DATA_LOAN_GRANTED,CONTRACT,GROSS,TOT_AMORT,TOT_REPAYMENT,OB_PRINCIPAL,INT_SUR,OB_TOT,LEAVE_WITHOUT_PAY,ACTUAL_LENGTH_OF_SERVICE,RCS,ACT_LNGTH_SRV_WITHOUT
'2000133249','NERA','A','GALAN',,'NERA A GALAN ','BICOL UNIV COLLEGE OF NURSING','LEGASPI CITY  ALBAY','1000000853','1969-03-25','March 25, 1969','69032501435','006000188531','COMPULSORY','PUROK 4 ROVER SUBD TUGOS CITY OF SORSOGON SORSOGON',,'00000010000003138060','CM00003730951',13170.24,17560.32,0.00,0.00,0.00,0.00,0.00,0.00,,,,,,,,,,0E-8,,0E-8,
4

1 回答 1

0

它很可能在var1、或var2中。(例如,它可能是“Smith & Jones”的公司名称。当然,考虑到它们过于通用的名称,我们不知道这些变量中的内容。)var3var4

这就是为什么您应该使用 XML API 构建 XML,它可以为您执行任何适当的转义。这与使用字符串连接来构建包含用户输入的 SQL 语句而不是使用参数化 SQL 基本上是相同的错误——只是形式略有不同。

于 2013-09-04T08:20:48.447 回答