我正在用 C# 创建 XML。我想附加item
到content
. 我用 . 创建了一个 XmlNode CreateItem
,但我似乎无法将它附加到contentElement
.
XmlDocument doc = new XmlDocument();
XmlNode contentElement = doc.CreateElement("content");
doc.AppendChild(contentElement);
contentElement.AppendChild(CreateItem);
public XmlNode CreateItem(XmlDocument doc, string hint, string type, string title, string value) {
XmlNode item = doc.CreateElement("item");
XmlAttribute Hint = doc.CreateAttribute("Hint");
Hint.Value = hint;
XmlAttribute Type = doc.CreateAttribute("Type");
Type.Value = type;
item.Attributes.Append(Hint);
item.Attributes.Append(Type);
XmlNode tit = doc.CreateElement("Title");
tit.InnerText = title;
item.AppendChild(tit);
XmlNode val = doc.CreateElement("Value");
val.InnerText = value;
item.AppendChild(val);
return item;
}