我从 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;
}
}
}
}
而且我不确定在注释掉代码的地方该怎么做。有什么建议么?关于如何提高效率的提示也将不胜感激。
提前致谢。