xml文件的有效性验证

ajiang1234 ajiang1234 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我把导入到datagrid的xml文件进行一次有效性验证,代码如下:
Public Class Form1
Public ReadOnly Property schemafilename() As String
Get
Dim fileinfo As New IO.FileInfo(Application.ExecutablePath)
Dim foldername As String = fileinfo.DirectoryName
Return foldername & "\xbrlwendang.xml"
End Get
End Property
Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click
dlgopenfile.Filter = "XML Files(*.xml)|*.xml|ALL Files(*.*)|*.*||"
If dlgopenfile.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
Dim newdataset As New DataSet
newdataset.ReadXmlSchema(schemafilename)
Dim reader As New Xml.XmlTextReader(dlgopenfile.FileName)
Dim validatingreader As New Xml.XmlValidatingReader(reader)
validatingreader.Schemas.Add(Nothing, schemafilename)
Do While True
If validatingreader.Read = False Then
Exit Do
End If
Loop
reader.Close()
validatingreader.Close()
newdataset.ReadXml(dlgopenfile.FileName)
Me.DataGrid1.DataSource = newdataset

Catch ex As Exception
If ex.GetType Is GetType(Xml.Schema.XmlSchemaException) Then
MsgBox("the xml file is not valid:" & ex.Message)
Else
MsgBox("a general exception occured:" & ex.Message)
End If
End Try
End If
End Sub
End Class
可是不管我导入哪一个可以通过IE打开的xml文件,都出现了如下提示:
the xml file is not valid:应为架构根。请确保根元素是<schema>,并且命名空间为“http://www3.org/2001/XMLSchema”(对于XSD架构)或"urn:schemas-microsoft-com:xml-data"(对于XDR架构)
求解答
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
ajiang1234
VB 16,718 成员 110,520 内容