2017-09-08 15 views
0

xml 파일을 자동으로 vallidate하려면이 코드가 필요합니다. 그것을 확인할 필요가 없습니다. 그래서 방법?vb net 통과 크리스탈 리포트에서 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

검증 무엇에 대한 XML을 처리 할 수 ​​있을까? XML이 유효한 XML인지 또는 XSD에 대해 파일의 유효성을 검사하겠습니까? –

답변

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