我有这段代码用于在 XML 文件中循环报告:
Dim xmlr As XDocument = XDocument.Load("Myfile.xml")
For Each report As XElement In xmlr.Descendants("Report")
'Do stuff with report values
Next
这可行,但如果文件包含 ÅÄÖ 之类的字符,我会收到错误消息。xml 文档的编码为 UFT-8;
<?xml version="1.0" encoding="utf-8"?>
我在这里找到了这篇文章,并尝试使用此代码,但没有帮助;
Dim xmlr As XDocument
Using oReader As StreamReader = New StreamReader("Myfile.xml", Encoding.GetEncoding("UTF-8"))
xmlr = XDocument.Load(oReader)
End Using
有什么建议么?