我想使用 Metro 风格应用程序(.Net Framework 4.5)在 XML 文件中写入一些数据。
这是我编写的代码,它工作正常,但问题是整个字符串是用单行而不是 XML 文本格式编写的。因此我无法正确阅读。每次我需要重新格式化新添加的数据以正确理解它。
这是我写的代码:
Dim f As New FolderPicker
f.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
f.ViewMode = PickerViewMode.Thumbnail
f.FileTypeFilter.Add("*")
Dim folder As StorageFolder = Await f.PickSingleFolderAsync
Dim rootEle As XmlElement
Dim file As StorageFile = Nothing
file = Await folder.CreateFileAsync("demoXML.xml", CreationCollisionOption.ReplaceExisting)
rootEle = doc.CreateElement("files_tbl")
doc.AppendChild(rootEle)
Dim ele As XmlElement
ele = doc.CreateElement("files")
rootEle.AppendChild(ele)
Dim otherEle As XmlElement
otherEle = doc.CreateElement("field-1")
otherEle.InnerText = "data-1"
ele.AppendChild(otherEle)
otherEle = doc.CreateElement("field-2")
otherEle.InnerText = "data-2"
ele.AppendChild(otherEle)
Await doc.SaveToFileAsync(file)
如果我想要这样的输出:
<files_tbl>
<files>
<field-1>data-1</field-1>
<field-2>data-2</field-2>
</files>
</files_tbl>
实际上我想使用那个 xml 文件作为我的数据库,因为我不想存储大量数据。我只需要存储文件的一些属性,例如文件名、扩展名、位置等。
可以使用xml文件作为数据库吗???