我想弄清楚如何移植一些解析xml文件到WinRT的.Net代碼。到目前爲止,在The given System.Uri cannot be converted into a Windows.Foundation.Uri的幫助下,我有下面的代碼。儘管如此,我被卡住後,立即創建開放的:如何用WinRT打開一個打包的文件
static readonly Uri ResourcesBase = new Uri(@"ms-resource://MyAssembly/");
public override async void Load()
{
Uri uri = new Uri(ResourcesBase, filePath); // filePath = "Data//world.xml";
XmlLoadSettings settings = new XmlLoadSettings() { ValidateOnParse = false };
XmlDocument xmlDoc = await XmlDocument.LoadFromUriAsync(uri, settings);
foreach (IXmlNode xmlNode in xmlDoc.ChildNodes)
{
ProcessNode(xmlNode);
}
}
我得到一個未處理的異常,當我嘗試調用XmlDocument.LoadFromUriAsyn(URI):
ArgumentException的是由用戶代碼未處理的 - 值不不在預期範圍內。
其他人覺得所有的事情都比WinRT困難10倍?
編輯:
我已經嘗試了所有下列字符串,並得到確切的同樣的錯誤:
Uri uri = new Uri("ms-resource://MyAssembly//" + filePath);
Uri uri = new Uri("ms-resource://MyAssembly/" + filePath);
Uri uri = new Uri("d:\\projects\\crystal\\" + filePath); // A valid absolute path
項目設置:
項目
- 屬性
- 參考文獻 個
- 資產
- 數據
- world.xml
- 源代碼
代碼:
filePath = "Data\\world.xml";
我也曾嘗試把XML文件在assset \ data下,只是資產。沒有什麼似乎有所作爲。
另一件事,我有xml設置爲「內容」的生成操作。那是對的嗎?我可以想象的唯一的另一件事是「嵌入式資源」,但我對此表示懷疑。
全部異常詳細信息:
System.ArgumentException是由用戶代碼
的HResult = -2147024809
消息=值不在所述預期範圍內未處理的。
源= Windows.Data.Xml.Dom
堆棧跟蹤:
在Windows.Data.Xml.Dom.XmlDocument.LoadFromUriAsync(URI的URI,XmlLoadSettings loadSettings)
在Crystal.IO .File.XmlFileSerializer.d__1.MoveNext()在d:\ Projects \ Crystal \ library \ IO \ File \ XmlFileSerializer中。CS:行32
的InnerException:
下載儘可能小的例子,瑞普問題:test_xml.zip
難道你不應該只有一個斜線?即'Uri uri = new Uri(「ms-resource:// MyAssembly /」+ filePath);'。 – 2012-03-04 13:11:04
只有1個尾部斜線或絕對文件路徑(c:\ ...)都沒有不同的效果。 – 2012-03-04 18:13:23
你能告訴我們什麼'filePath'看起來像? – user7116 2012-03-04 20:47:37