using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace CY.Infrastructure.XML
{
///
/// XmlNode访问器接口
///
interface IXmlNodeVisitor
{
///
/// 设置当前访问器结点
///
/// 当前要访问的节点信息
void SetNode(XmlNode __xmlNode);
///
/// 返回当前访问器所用结点信息
///
///
///
XmlNode GetNode(string __nodeName);
///
/// 索引器属性
///
/// 节点名称
///
string this[string __nodeName] { get; set; }
}
///
/// 属性节点Value访问器类
///
public class XmlNodeAttributeValueVisitor : IXmlNodeVisitor
{
private XmlNode xmlNode;
public XmlNodeAttributeValueVisitor()
{ }
///
/// 定义索引器
///
///
///
public string this[string __nodeName]
{
get
{
return xmlNode.Attributes[__nodeName].Value;
}
set
{
xmlNode.Attributes[__nodeName].Value = value;
}
}
///
/// 设置当前访问器结点
///
/// 当前要访问的节点信息
public void SetNode(XmlNode __xmlNode)
{
xmlNode = __xmlNode;
}
///
/// 返回当前访问器所用结点信息
///
/// 节点名称
///
public XmlNode GetNode(string __nodeName)
{
return xmlNode.SelectSingleNode(__nodeName);
}
}
///
/// Select节点InnerText访问器类
///
public class XmlNodeInnerTextVisitor : IXmlNodeVisitor
{
private XmlNode xmlNode;
public XmlNodeInnerTextVisitor()
{ }
///
/// 定义索引器
///
///
///
public string this[string __nodeName]
{
get
{
return xmlNode.SelectSingleNode(__nodeName).InnerText;
}
set
{
xmlNode.SelectSingleNode(__nodeName).InnerText = value;
}
}
///
/// 设置当前访问器结点
///
/// 当前要访问的节点信息
public void SetNode(XmlNode __xmlNode)
{
xmlNode = __xmlNode;
}
///
/// 返回当前访问器所用结点信息
///
/// 节点名称
///
public XmlNode GetNode(string __nodeName)
{
return xmlNode.SelectSingleNode(__nodeName);
}
}
}