您可以使用 System.XML 命名空间来执行此操作。当然你也可以使用 LINQ。但我选择了 .NET 2.0 方法,因为我不确定您使用的是哪个版本的 .NET。
XmlDocument doc = new XmlDocument();
// Create the Where Node
XmlNode whereNode = doc.CreateNode(XmlNodeType.Element, "Where", string.Empty);
XmlNode eqNode = doc.CreateNode(XmlNodeType.Element, "Eq", string.Empty);
XmlNode fieldNode = doc.CreateNode(XmlNodeType.Element, "Field", string.Empty);
XmlAttribute newAttribute = doc.CreateAttribute("FieldName");
newAttribute.InnerText = "Name";
fieldNode.Attributes.Append(newAttribute);
XmlNode valueNode = doc.CreateNode(XmlNodeType.Element, "Value", string.Empty);
XmlAttribute valueAtt = doc.CreateAttribute("Type");
valueAtt.InnerText = "Text";
valueNode.Attributes.Append(valueAtt);
// Can set the text of the Node to anything.
valueNode.InnerText = "Value Text";
// Or you can use
//valueNode.InnerXml = "<aValid>SomeStuff</aValid>";
// Create the document
fieldNode.AppendChild(valueNode);
eqNode.AppendChild(fieldNode);
whereNode.AppendChild(eqNode);
doc.AppendChild(whereNode);
// Or you can use XQuery to Find the node and then change it
// Find the Where Node
XmlNode foundWhereNode = doc.SelectSingleNode("Where/Eq/Field/Value");
if (foundWhereNode != null)
{
// Now you can set the Value
foundWhereNode.InnerText = "Some Value Text";
}