62,046
社区成员
发帖
与我相关
我的任务
分享
<TablePath ID="CSI_HIS_PRICES" Path="bonddata/csibond/historical_prices" Description="中证债券指数当前行情" UpdateToDay="false">
<Column ID="凸性_Convexity" ColumnName="Convexity" DBType="" DATAType="String" DefaultValue=""></Column>
<Column ID="到期收益率(%)_YieldToMaturity(%)" ColumnName="Maturity" DBType="" DATAType="String" DefaultValue=""></Column>
</TablePath>
<!-- 以下还没有建表-->
<TablePath ID="BOND_constituents" Path="bonddata/csibond/constituents_list" Description="最新样本数据" UpdateToDay="false">
<Column ID="日期_Date" ColumnName="DATE" DBType="Key" DATAType="Date" DefaultValue=""></Column>
<Column ID="成分券代码_ConstituentCode" ColumnName="Constituent_Code" DBType="Key" DATAType="Int" DefaultValue=""></Column>
<Column ID="成分券名称_ConstituentName" ColumnName="Constituent_Name" DBType="" DATAType="String" DefaultValue=""></Column>
</TablePath>
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe = xn as XmlElement;//最好不好用强制转换,建议使用as,这样如果转不过去话,就是null,不会报异常
if(xe!=null) //这样判断以下是否为null,或者你可以if(xe==null) return ;直接返回或做其他处理
{
Keyname = xe.Attributes["key"].InnerXml;//键值
switch (Keyname)
{
case "SiteName":
xe.Attributes["value"].Value = this.txtSiteName.Text;
break;
case "Sitecontent":
xe.Attributes["value"].Value = this.txtDescription.Text;
}
public string GetConnectionString()
{
return (IsExistKey("appSettings", appSettingsKey)) ? ConfigurationManager.AppSettings[appSettingsKey] : string.Empty;
}
private string GetXmlFileName()
{
return HttpContext.Current.Server.MapPath("~/Web.config");
}
private XmlDocument GetWebConfig()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(GetXmlFileName());
return xmlDoc;
}
public bool IsExistNode(string strNode)
{
XmlDocument xmlDoc = GetWebConfig();
XmlNode xmlNode = xmlDoc.SelectSingleNode(@"/" + strNode);
// retrieve the appSettings xmlNode
xmlNode = xmlDoc.SelectSingleNode("//" + strNode);
return (xmlNode != null);
}
public bool IsExistKey(string strNodeName, string strKey)
{
XmlDocument xmlDoc = GetWebConfig();
bool IsExist = false;
//在当前所有节点中循环查找
XmlNodeList topM = xmlDoc.DocumentElement.ChildNodes;
foreach (XmlElement element in topM)
{
//判断是否存在<appSettings>节点
if (element.Name == strNodeName)
{
XmlNodeList node = element.ChildNodes;
//判断是否存在定义的信息
if (node.Count > 0)
{
//在子节点中循环查找
foreach (XmlElement el in node)
{
//判断Key是否等于所需信息Liumm
IsExist = (el.Attributes["key"].InnerXml == strKey);
if (IsExist) break;
}
}
}
}
return IsExist;
}
public void SetValue(string key, string value)
{
XmlDocument xmlDoc = GetWebConfig();
XmlNode xmlNode = xmlDoc.SelectSingleNode(@"/appSettings");
// retrieve the appSettings xmlNode
xmlNode = xmlDoc.SelectSingleNode("//appSettings");
if (xmlNode == null)
{
throw new InvalidOperationException("appSettings section not found");
}
try
{
// XPath select setting "add" element that contains this key
XmlElement addElem = (XmlElement)xmlNode.SelectSingleNode("//add[@key='" + key + "']");
if (addElem != null)
{
addElem.SetAttribute("value", value);
}
// not found, so we need to add the element, key and value
else
{
XmlElement entry = xmlDoc.CreateElement("add");
entry.SetAttribute("key", key);
entry.SetAttribute("value", value);
xmlNode.AppendChild(entry);
}
//save it
try
{
XmlTextWriter writer = new XmlTextWriter(GetXmlFileName(), null);
writer.Formatting = Formatting.Indented;
xmlDoc.WriteTo(writer);
writer.Flush();
writer.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
catch (Exception ex)
{
throw new InvalidOperationException(ex.Message);
}
}