SHARE
TWEET

Untitled

a guest Jan 15th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub XmlDocumentWalker(XmlNode As XmlNode)
  2.  
  3.     If TypeOf XmlNode Is XmlComment Then
  4.  
  5.         MsgBox(XmlNode.Value, MsgBoxStyle.OkOnly, "XML Comment")
  6.  
  7.         If XmlNode.HasChildNodes Then XmlDocumentWalker(XmlNode.FirstChild)
  8.         If Not IsNothing(XmlNode.NextSibling) Then XmlDocumentWalker(XmlNode.NextSibling)
  9.  
  10.     ElseIf TypeOf XmlNode Is XmlElement Then
  11.  
  12.         If XmlNode.HasChildNodes And (TypeOf XmlNode.FirstChild Is XmlText) Then
  13.  
  14.             MsgBox(XmlNode.Name & "=""" & XmlNode.FirstChild.Value & """", MsgBoxStyle.OkOnly, "XML Element")
  15.  
  16.         Else
  17.  
  18.             MsgBox(XmlNode.Name, MsgBoxStyle.OkOnly, "XML Element")
  19.  
  20.         End If
  21.  
  22.         If DirectCast(XmlNode, XmlElement).HasAttributes Then
  23.             For Each XmlAttribute As XmlNode In DirectCast(XmlNode, XmlElement).Attributes
  24.  
  25.                 MsgBox(XmlAttribute.Name & "=""" & XmlAttribute.Value & """", MsgBoxStyle.OkOnly, "XML Attribute")
  26.  
  27.             Next
  28.         End If
  29.  
  30.         If XmlNode.HasChildNodes And Not (TypeOf XmlNode.FirstChild Is XmlText) Then XmlDocumentWalker(XmlNode.FirstChild)
  31.         If Not IsNothing(XmlNode.NextSibling) Then XmlDocumentWalker(XmlNode.NextSibling)
  32.     End If
  33. End Sub
  34.    
  35. Private XmlDocument As XmlDocument
  36.  
  37. Private ValidationErrorCount As Integer
  38.  
  39. Public Sub Load()
  40.     ValidationErrorCount = 0
  41.  
  42.     Try
  43.         Dim XmlReader As XmlReader
  44.         Dim XmlReaderSettings As New XmlReaderSettings()
  45.         Dim ValidationEventHandler As New ValidationEventHandler(AddressOf XMLValidationErrorMessage)
  46.  
  47.         XmlReaderSettings.ValidationType = ValidationType.DTD
  48.         XmlReaderSettings.DtdProcessing = DtdProcessing.Parse
  49.  
  50.         AddHandler XmlReaderSettings.ValidationEventHandler, ValidationEventHandler
  51.  
  52.         XmlReader = XmlReader.Create(FileName, XmlReaderSettings)
  53.  
  54.         XmlDocument = New XmlDocument()
  55.  
  56.         XmlDocument.Load(XmlReader)
  57.  
  58.         If 0 = ValidationErrorCount Then
  59.             XmlDocumentWalker(XmlDocument)
  60.         End If
  61.  
  62.     Catch Exception As Exception
  63.         XmlDocument = Nothing
  64.         MsgBox(Exception.Message, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Configuration file load error")
  65.     End Try
  66. End Sub
  67.  
  68. Private Sub XMLValidationErrorMessage(ByVal sender As Object, ByVal args As ValidationEventArgs)
  69.     If 0 = ValidationErrorCount Then
  70.         MsgBox(ConfigurationResource, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Configuration file invalid")
  71.     End If
  72.  
  73.     MsgBox(args.Message, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "XML format error")
  74.  
  75.     ValidationErrorCount += 1
  76. End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top