//读取
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xml);
XmlNode XNSpec
= xmlDoc.SelectSingleNode("spec");
XmlNodeList XLlist
= XNSpec.ChildNodes; //读取所有节点

foreach (XmlNode xnnode in XLlist)
{
if (xnnode.Name.ToLower() == specname)
{
returnStr
= xnnode.InnerText.Trim();
}
}

// 插入
      System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
      xmlDoc.LoadXml(xml);
XmlNode XNSpec
= xmlDoc.SelectSingleNode("spec");
XmlNodeList XLlist
= XNSpec.ChildNodes;

foreach (XmlNode xnnode in XLlist)
{
if (xnnode.Name.ToLower() == lowspecname)
{
xnnode.InnerText
= specvalue;
hasSetted
= true;
}
}

// 若没有设定过则需要添加字段
if (!hasSetted)
{
XmlElement elem
= xmlDoc.CreateElement(specname);
elem.InnerText
= specvalue;
XNSpec.AppendChild(elem);
}

相关文章:

  • 2021-09-28
  • 2021-11-13
  • 2021-10-12
  • 2021-07-05
猜你喜欢
  • 2022-12-23
  • 2021-06-03
  • 2021-06-10
  • 2021-05-27
  • 2021-09-14
  • 2021-10-20
  • 2022-01-14
相关资源
相似解决方案