コードを使用して XML ファイルを作成しようとしています。ファイルは正常に作成されていますが、ファイルに必要なシステムは UTF-8 しか読み取れません。いくつかの隠し文字があるため、ファイルは正常にロードされていません。
この隠し文字はエラーになります。ボムを 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 を作成します。
最後に、以下に示すように、すべての XElements を XDocument に格納して、XML スタイル ドキュメントを作成し、ファイルを .XPO として保存します。
XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xdoc.Save(pathDesktop + "\\22CRE002.XPO");