我对编程很新,我想通过xml创建一个新的键值对文档发送到Web服务
<BuildAddOns>
<UserInput Question="foo" Answer="blahh" Type="String" />
<UserInput Question="foo" Answer="blahh" Type="String" />
</BuildAddOns>
答案 0 :(得分:0)
您可以使用XDocument
来读取/写入xml文件。这是代码:
XElement root = new XElement("BuildAddOns");
XDocument doc = new XDocument(root);
XElement element1 = new XElement("UserInput");
element1.SetAttributeValue("Question", "foo");
element1.SetAttributeValue("Answer", "blahh");
element1.SetAttributeValue("Type", "String");
doc.Root.Add(element1);
XElement element2 = new XElement("UserInput");
element2.SetAttributeValue("Question", "foo");
element2.SetAttributeValue("Answer", "blahh");
element2.SetAttributeValue("Type", "String");
doc.Root.Add(element2);
doc.Save(@"C:\New Text Document.txt");