如何写数据到XML文件的Windows Phone? [英] How to write data in to Xml File Windows Phone?
问题描述
我要动态地创建一个XML文件。创建文件后,我想通过在 C# Windows Phone的编码来创建XML文件中的结构如下:
I want to create a XML file dynamically. After creating the file, I want to create a following structure in XML file by coding in c# windows phone.
<Contacts>
<Contact>
<Name>ABC</Name>
<PhoneNumber>1234</PhoneNumber>
<Email>abc@abc.com</Email>
</Contact>
</Contacts>
我要插入XML文件中,这些类型的数据。我寻觅它,我发现这个例子将数据添加到现有XML文件使用LINQ 。
但我不能够访问的的XDocument 在我的Windows Phone项目。我还添加了了System.XML 组装。
I want to insert these type of data in XML file. I have searched on it and I found this example add data to existing xml file using linq. But I am not able to access XDocument in my windows phone project. I have also added System.XML assembly.
所以,我怎样才能插入XML文件中的数据?是否有可能在Windows手机?
So, How can I insert data in XML file? Is it possible in windows phone?
推荐答案
的XDocument在System.Xml.Linq的命名空间。所以,在你的代码文件的顶部,添加:
XDocument is in System.Xml.Linq namespace. So, at the top of your code file, add:
using System.Xml.Linq;
然后就可以将数据写入到文件的方式如下:
Then you can write the data to your file the following way:
XDocument xDoc = XDocument.Load("file.xml");
var contactsElement = new XElement("Contacts",
new XElement("Contact",
new XElement("Name", "ABC"),
new XElement("PhoneNumber", "1234"),
new XElement("Email", "abc@abc.com")));
xDoc.Add(contactsElement);
xDoc.Save(...);
这篇关于如何写数据到XML文件的Windows Phone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!