[英]What is the best way to read an XML file from Embedded resources?
Dim xmldoc As New XmlDocument()
Dim xmlnode As XmlNodeList
Dim i As Integer
Dim str As String
xmldoc.LoadXml("countyByRegion.xml")
這拋出
System.Xml.dll中發生類型'System.Xml.XmlException'的異常,但未在用戶代碼中處理。 附加信息:根級別的數據無效。 第1行,位置1。
我通常會這樣做
Dim fsXML As New FileStream("countyByRegion.xml", FileMode.Open, FileAccess.Read)
然后使用xmldoc.Load(fsXML)
Dim fileText As String
Dim a As Assembly = GetType(ZP957_Form).Assembly
Using reader As New StreamReader(a.GetManifestResourceStream("ZP957.countyByRegion.xml"))
fileText = reader.ReadToEnd()
End Using
xmldoc.LoadXml(fileText)
由於xml是嵌入式的,因此必須從程序集中讀取它,因為我必須使用GetManifestResourceStream,然后可以執行LoadXml,因為現在有了xml的文件流。 這對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.