【发布时间】:2013-09-25 21:43:02
【问题描述】:
我正在尝试通过代码创建 XML 文件。该文件已成功创建,但该文件所需的系统仅读取 UTF-8。该文件未成功加载,因为它们是一些隐藏字符。
此隐藏字符生成错误。我在想我需要将 bom 设置为 false,但不知道如何设置。您可以在下面找到用于生成文件的代码。
XElement xElement = new XElement("Transaction",
new XElement("TransactionNumber", counter),
new XElement("TransactionReferenceNumber", "CRE" + payItem.ID),
new XElement("TransactionDate", DateTime.Today.Date.ToString("yyyy-MM-dd")),
new XElement("BankID", "99"),
new XElement("SourceAccountNumber", currentAccount.AccountNumber),
new XElement("BeneficiaryName", RemoveSpecialCharacters(payItem.WIRE_BENEF_NAME)),
new XElement("PaymentDetails1", details),
new XElement(checkForAccountDetails(payItem.WIRE_BENEF_BANK_IBAN), getIBANorNumber(payItem)),
new XElement("POCurrency", payItem.Currency),
new XElement("POAmount", payItem.NET_DEPOSIT),
new XElement("BeneficiaryType", "FINANCIAL"),
new XElement("Residence", "NON-RESIDENT"),
new XElement("IncurredChargesBy", "SHARED"),
new XElement("ExchangeControlClassification", "OTHER PAYMENTS"),
new XElement("TypeofPayment", "T3"),
new XElement("SectorCode", "COS"),
new XElement("Priority", getPaymentPriority(payItem.Currency)),
new XElement("SwiftAddress", payItem.WIRE_BENEF_BANK_SWIFT_CDE),
new XElement("BankCountry", currentBank.Country.ToUpper())
);
xDetail.Add(xElement);
基本上我使用的是 C# 和 XElement 类,它通过在参数中传递名称标签和数据来创建 XML。
最后,我将所有 XElement 存储在 XDocument 中,如下所示,以创建 XML 样式文档并将文件另存为 .XPO
XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xdoc.Save(pathDesktop + "\\22CRE002.XPO");
【问题讨论】:
标签: c# xml utf-8 character-encoding xelement