一个Cash.xml文件内容如下:<?xml version="1.0" encoding="utf-8" ?>
<Root>
<CashAccept Enable="true">
<Type>正常收费</Type>
</CashAccept>
<CashAccept Enable="false">
<Type>打8折</Type>
<Rebate>0.8</Rebate>
</CashAccept>
<CashAccept Enable="false">
<Type>满300返50</Type>
<MoneyCondition>300.0</MoneyCondition>
<MoneyReturn>50.0</MoneyReturn>
</CashAccept>
</Root>
现在我要在页面打开的时候,读取Enable="true"的节点,我这样做:class CashInfo
{
public bool Enable { get; set; }
public string Type { get;set;}
public string param1 { get; set; }
public string param2 { get; set; }}public class SetCash
{
XmlOperate xml = new XmlOperate();
private CashInfo ci;
public SetCash()
{
if (ci == null)
ci = new CashInfo();
XElement e = xml.SelectXElementByAttribute(@"~/App_Data/Cash.xml","Enable","true");
ci.Enable =(bool)e.Attribute("Enable");
ci.Type = (string)e.Element("Type");
//ci.param1和ci.param2如何赋值?
}}
public XElement SelectXElementByAttribute(string path, string attributeName, string attributeValue)
{
XElement returnXelement = null;
XElement xmlFile = this.LoadXmlFile(path);
IEnumerable<XElement> query = from el in xmlFile.Elements()
where (string)el.Attribute(attributeName) == attributeValue
select el;
foreach (XElement e in query)
returnXelement = e;
return returnXelement;
}
ci.param1和ci.param2如何赋值好呢?能不能不要修改Cash.xml文件里面的内容?
<Root>
<CashAccept Enable="true">
<Type>正常收费</Type>
</CashAccept>
<CashAccept Enable="false">
<Type>打8折</Type>
<Rebate>0.8</Rebate>
</CashAccept>
<CashAccept Enable="false">
<Type>满300返50</Type>
<MoneyCondition>300.0</MoneyCondition>
<MoneyReturn>50.0</MoneyReturn>
</CashAccept>
</Root>
现在我要在页面打开的时候,读取Enable="true"的节点,我这样做:class CashInfo
{
public bool Enable { get; set; }
public string Type { get;set;}
public string param1 { get; set; }
public string param2 { get; set; }}public class SetCash
{
XmlOperate xml = new XmlOperate();
private CashInfo ci;
public SetCash()
{
if (ci == null)
ci = new CashInfo();
XElement e = xml.SelectXElementByAttribute(@"~/App_Data/Cash.xml","Enable","true");
ci.Enable =(bool)e.Attribute("Enable");
ci.Type = (string)e.Element("Type");
//ci.param1和ci.param2如何赋值?
}}
public XElement SelectXElementByAttribute(string path, string attributeName, string attributeValue)
{
XElement returnXelement = null;
XElement xmlFile = this.LoadXmlFile(path);
IEnumerable<XElement> query = from el in xmlFile.Elements()
where (string)el.Attribute(attributeName) == attributeValue
select el;
foreach (XElement e in query)
returnXelement = e;
return returnXelement;
}
ci.param1和ci.param2如何赋值好呢?能不能不要修改Cash.xml文件里面的内容?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货