在vb net中读取xml传递水晶报告?

时间:2017-09-08 07:00:11

标签: vb.net crystal-reports crystal-reports-2008

我需要这个来自动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")

1 个答案:

答案 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