XML操作方法
来源:互联网 发布:点击淘宝旺旺没反应 编辑:程序博客网 时间:2024/05/09 18:33
///方法名:XPathQueryFromXml
///输入参数:
/// pFileName:文件名
/// pRoot:元素的根
/// pAttribute:属性名
/// pAttributeValue:属性值
///返回值:该元素的值,string类型
public XmlNode LoadValue(string xpath,int index)
{
XmlNodeList nl=xml.SelectNodes(xpath);
return nl.Item(index);
}
public string XPathFromXml(string pRoot,string pAttribute,string pAttributeValue)
{
string sValue="Error.";
string sXPath="//"+pRoot+"/*[@"+pAttribute+"='"+pAttributeValue+"']";
try
{
XmlNode nd=xml.SelectSingleNode(sXPath);
sValue=nd.InnerText.ToString();
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
return sValue;
}
///方法名:AddValueToXml
///功能:将指定的xmlnode加入指定文件的指定位置
///输入参数:
/// pFileName:文件名
/// pElementName:元素名
/// pValue:元素的值
/// pAttribute:属性名
/// pAttributeValue:属性值
/// pRoot:元素的根
///返回值:无
public void AddValueToXML(string pRoot,string pElementName,string pAttribute,string pAttributeValue,string pValue)
{
try
{
XmlElement root=xml.DocumentElement;
XmlNode nd=root[pRoot];
XmlElement nEl=xml.CreateElement(pElementName);
nEl.SetAttribute(pAttribute,pAttributeValue);
nEl.InnerText=pValue;
nd.AppendChild(nEl);
xml.Save(m_ConfigFileName);
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
}
///方法名:UpdateValueToXml by jsz at 2003.1.23
///功能:修改指定文件的指定位置,根据元素名+属性值匹配
///输入参数:
/// pFileName:文件名
/// pRoot:元素的根
/// pElementName:元素名
/// pAttribute:属性名
/// pAttributeValue:属性值
/// pValue:要更换的元素值
///返回值:bool类型,标识成功与否
public bool UpdateValueToXML(string pRoot,string pElementName,string pAttribute,string pAttributeValue,string pValue)
{
bool sValue=false;
string sXPath="//"+pRoot+"/"+pElementName+"[@"+pAttribute+"='"+pAttributeValue+"']";
try
{
XmlNode nd=xml.SelectSingleNode(sXPath);
nd.InnerText =pValue;
xml.Save(m_ConfigFileName);
sValue=true;
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
return sValue;
}
///方法名:DeleteFromXml by jsz at 2003.1.23
///功能:从指定文件的指定位置删除节点,根据元素名+属性值匹配
///输入参数:
/// pFileName:文件名
/// pRoot:元素的根
/// pElementName:元素名
/// pAttribute:属性名
/// pAttributeValue:属性值
///返回值:bool类型,标识成功与否
public bool DeleteFromXML(string pRoot,string pElementName,string pAttribute,string pAttributeValue)
{
bool sValue=false;
string sXPath="//"+pRoot+"/"+pElementName+"[@"+pAttribute+"='"+pAttributeValue+"']";
string sXPathRoot="//"+pRoot;
try
{
XmlNode nd=xml.SelectSingleNode(sXPath);
XmlNode root=xml.SelectSingleNode(sXPathRoot);
nd.RemoveChild(nd);
xml.Save(m_ConfigFileName);
sValue=true;
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
return sValue;
}
///输入参数:
/// pFileName:文件名
/// pRoot:元素的根
/// pAttribute:属性名
/// pAttributeValue:属性值
///返回值:该元素的值,string类型
public XmlNode LoadValue(string xpath,int index)
{
XmlNodeList nl=xml.SelectNodes(xpath);
return nl.Item(index);
}
public string XPathFromXml(string pRoot,string pAttribute,string pAttributeValue)
{
string sValue="Error.";
string sXPath="//"+pRoot+"/*[@"+pAttribute+"='"+pAttributeValue+"']";
try
{
XmlNode nd=xml.SelectSingleNode(sXPath);
sValue=nd.InnerText.ToString();
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
return sValue;
}
///方法名:AddValueToXml
///功能:将指定的xmlnode加入指定文件的指定位置
///输入参数:
/// pFileName:文件名
/// pElementName:元素名
/// pValue:元素的值
/// pAttribute:属性名
/// pAttributeValue:属性值
/// pRoot:元素的根
///返回值:无
public void AddValueToXML(string pRoot,string pElementName,string pAttribute,string pAttributeValue,string pValue)
{
try
{
XmlElement root=xml.DocumentElement;
XmlNode nd=root[pRoot];
XmlElement nEl=xml.CreateElement(pElementName);
nEl.SetAttribute(pAttribute,pAttributeValue);
nEl.InnerText=pValue;
nd.AppendChild(nEl);
xml.Save(m_ConfigFileName);
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
}
///方法名:UpdateValueToXml by jsz at 2003.1.23
///功能:修改指定文件的指定位置,根据元素名+属性值匹配
///输入参数:
/// pFileName:文件名
/// pRoot:元素的根
/// pElementName:元素名
/// pAttribute:属性名
/// pAttributeValue:属性值
/// pValue:要更换的元素值
///返回值:bool类型,标识成功与否
public bool UpdateValueToXML(string pRoot,string pElementName,string pAttribute,string pAttributeValue,string pValue)
{
bool sValue=false;
string sXPath="//"+pRoot+"/"+pElementName+"[@"+pAttribute+"='"+pAttributeValue+"']";
try
{
XmlNode nd=xml.SelectSingleNode(sXPath);
nd.InnerText =pValue;
xml.Save(m_ConfigFileName);
sValue=true;
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
return sValue;
}
///方法名:DeleteFromXml by jsz at 2003.1.23
///功能:从指定文件的指定位置删除节点,根据元素名+属性值匹配
///输入参数:
/// pFileName:文件名
/// pRoot:元素的根
/// pElementName:元素名
/// pAttribute:属性名
/// pAttributeValue:属性值
///返回值:bool类型,标识成功与否
public bool DeleteFromXML(string pRoot,string pElementName,string pAttribute,string pAttributeValue)
{
bool sValue=false;
string sXPath="//"+pRoot+"/"+pElementName+"[@"+pAttribute+"='"+pAttributeValue+"']";
string sXPathRoot="//"+pRoot;
try
{
XmlNode nd=xml.SelectSingleNode(sXPath);
XmlNode root=xml.SelectSingleNode(sXPathRoot);
nd.RemoveChild(nd);
xml.Save(m_ConfigFileName);
sValue=true;
}
catch(Exception E)
{
ApplicationLog.WriteLog(E.ToString());
}
return sValue;
}
- XML操作方法
- XML操作方法
- XML操作方法
- .net xml常用操作方法
- XML各种操作方法汇集
- .net xml常用操作方法
- C#:Xml操作方法
- xml文件基本操作方法集合
- 实例解析Js+XML的操作方法
- 实例解析Js+XML的操作方法
- 脚本代码:实例解析Js+XML的操作方法
- 脚本代码:实例解析Js+XML的操作方法
- 脚本代码:实例解析Js+XML的操作方法
- c#里xml格式文件的新增、修改、删除操作方法
- quartz定时执行任务,并配置web.xml的操作方法
- jQuery 文档操作方法大全(也适用于 XML 文档和 HTML 文档)
- 键盘操作方法
- 豪盛手台操作方法
- Interceptor和它要截取得class在一个package下时,Interceptor自身不能出现在被截取得表达式中,比如使用了*
- 2000/XP命令行一次运行多个命令
- 软件质量保证的大体思想
- 由鸬鹚罢工想到的
- 开张!
- XML操作方法
- ORDER BY xxx DESC/ASC
- J2ME国外站点
- Very good sincere advice
- Oracle培训教材
- 网虫半日速成手册
- 自增量identity(1,1)快到头了,不改变字段类型的话,怎么解决
- MyBase 启动之日
- XSLT轻松入门第一章:XSLT的概念