110,538
社区成员
发帖
与我相关
我的任务
分享
<CISBORDERGUESTS>
<GUEST OPERATION="DJ">
<GPHOTO >
/9j/4AAQSkZJRgABAgEAZABkAA
</GPHOTO>
</GUEST>
</CISBORDERGUESTS>
#region 设置节点的属性值
/// <summary>
/// 设置节点的属性值
/// </summary>
/// <param name="xmlNodePath">节点名称</param>
/// <param name="xmlNodeAttribute">属性名称</param>
/// <param name="xmlNodeAttributeValue">属性值</param>
public void SetXmlNodeAttributeValue(string xmlNodePath, string xmlNodeAttribute, string xmlNodeAttributeValue)
{
try
{
//可以批量为符合条件的节点的属性赋值
XmlNodeList xmlNode = this.xmlDoc.SelectNodes(xmlNodePath);
if (!(xmlNode == null))
{
if (xmlNode.Count == 1)
{
foreach (XmlNode xn in xmlNode)
{
XmlAttributeCollection xmlAttr = xn.Attributes;
for (int i = 0; i < xmlAttr.Count; i++)
{
if (xmlAttr.Item(i).Name == xmlNodeAttribute)
{
xmlAttr.Item(i).Value = xmlNodeAttributeValue;
break;
}
}
}
}
else
if (xmlNode.Count > 1)
{
int count = 1;
foreach (XmlNode xn in xmlNode)
{
if (xmlNode.Count == count)
{
XmlAttributeCollection xmlAttr = xn.Attributes;
for (int i = 0; i < xmlAttr.Count; i++)
{
if (xmlAttr.Item(i).Name == xmlNodeAttribute)
{
xmlAttr.Item(i).Value = xmlNodeAttributeValue;
break;
}
}
}
count++;
}
}
}
}
catch (XmlException xmle)
{
throw xmle;
}
}
#endregion