名前や住所などの顧客データが記載された石鹸の封筒をWebサービスから受け取ります。住所には市/郊外ではなく郵便番号が含まれています。私はすべての市と郊外の郵便番号をCSVファイルに入れているので、各郵便番号に正しい名前を挿入したいと思います。データベースなどに保存できますが、これはデータを渡す前にノードを挿入する方法に関するものです。
コードは次のようなものです:
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(searchResponse);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable);
nsmgr.AddNamespace("ns", wsNamespace);
XmlNodeList postCodeNodes = xDoc.SelectNodes("//ns:postcode", nsmgr);
string applicationPath = AppDomain.CurrentDomain.BaseDirectory;
foreach (XmlNode node in postCodeNodes)
{
using (StreamReader readFile = new StreamReader(applicationPath + "postcodes.csv"))
{
string line;
string[] row;
while ((line = readFile.ReadLine()) != null)
{
row = line.Split(',');
if (row[0].ToString() == node.InnerText)
{
string suburb = row[1].ToString();
//XmlNode ndSuburb = xDoc.CreateElement("suburb");
//ndSuburb.Value = suburb;
//node.ParentNode.AppendChild(ndSuburb);
break;
}
}
}
}
コードをコメントアウトした場所で何をすべきかわかりません。助言がありますか?これをより効率的にするためのヒントもいただければ幸いです。
前もって感謝します。