我需要这个来自动vallidate xml文件。无需验证。怎么样?
Dim document As XDocument = XDocument.Load("C:\Purchase Request Setup\Crystal reports\crptPurchaseRequest.xml")
这是如何读取xml?
或
dt.ReadXml("C:\Purchase Request Setup\Crystal reports\crptPurchaseRequest.xml")
答案 0 :(得分:0)
有几种方法可以验证XML ...
Public Shared Function IsValidXml(xmlString As String) As Boolean
Dim tagsWithData As New Regex("<\w+>[^<]+</\w+>")
If String.IsNullOrEmpty(xmlString) OrElse tagsWithData.IsMatch(xmlString) = False Then
Return False
End If
Try
Dim xmlDocument As New XmlDocument()
xmlDocument.LoadXml(xmlString)
Return True
Catch xmlException As XmlException
Return False
End Try
End Function
N.B。取自here
或者你可以简单地处理异常
Try
Dim document As XDocument = XDocument.Load("C:\Purchase Request Setup\Crystal reports\crptPurchaseRequest.xml")
Catch ex As XmlException 'Handle the exception
'Probably poorly formed XML...
End Try