Imports System.IO Imports System.Xml Imports System.Xml.Schema Module XMLHandling #Region "Members" Private _validationSuccess As Boolean #End Region Public Stamm1 As Stammdaten #Region "Public Functions" Public Function Load(ByVal strData As String) As Boolean Dim result As Boolean = True Try '----Read Data---- If result Then Dim doc As New XmlDocument() doc.LoadXml(strData) Stamm1 = New Stammdaten If Not (Stamm1.fill(doc)) Then m_log.Log("EDKB04: Fehler beim Einlesen des XML", Common.Common.JournalEntryType.Error) result = False End If End If '----VALIDIERUNG---- If result Then 'm_log.Log("EDKB04: Validierung START", Common.Common.JournalEntryType.Information) '-----HEADER----- If Not Stamm1.HasResultHeader Then result = False m_log.Log("EDKB04: Kein ResultHeader in XML vorhanden", Common.Common.JournalEntryType.Error) End If '-----PartnerNAT----- If result And Stamm1.HasPartnerNat Then If Stamm1._ResultContent._partnerNat._partnerNummer = "" Then Stamm1.HasPartnerNat = False result = False m_log.Log("EDKB04: Fehler in PartnerNat, keine Partnernummer", Common.Common.JournalEntryType.Error) End If End If '-----PartnerJUR----- If result And Stamm1.HasPartnerJur Then If Stamm1._ResultContent._partnerJur._partnerNummer = "" Then Stamm1.HasPartnerJur = False result = False m_log.Log("EDKB04: Fehler in PartnerJur, keine Partnernummer", Common.Common.JournalEntryType.Error) End If End If '-----PartnerHauptadresse----- If result And Stamm1.HasHauptadresse Then If Stamm1._ResultContent._hauptAdresse._objektRefNr = "" Then Stamm1.HasHauptadresse = False result = False m_log.Log("EDKB04: Fehler in Hauptadresse, keine Partnernummer", Common.Common.JournalEntryType.Error) End If End If '-----Versandadresse----- If result And Stamm1.HasVersandadresse Then If Stamm1._ResultContent._versandAdresse._objektRefNr = "" Then Stamm1.HasVersandadresse = False result = False m_log.Log("EDKB04: Fehler in VersandAdresse, keine Partnernummer", Common.Common.JournalEntryType.Error) End If If result And Stamm1._ResultContent._versandAdresse._objektNr = "" Then Stamm1.HasVersandadresse = False result = False m_log.Log("EDKB04: Fehler in VersandAdresse, keine objektNr (Bezug zu Partnernummer Versandadresse)", Common.Common.JournalEntryType.Error) End If End If '-----Mitarbeiter----- '-----VV----- If result And Stamm1.HasVV Then If Stamm1._ResultContent._vv._PartnerNummer = "" Then Stamm1.HasVV = False result = False m_log.Log("EDKB04: Fehler in VV, keine Partnernummer", Common.Common.JournalEntryType.Error) End If End If If result Then 'm_log.Log("EDKB04: Validierung ENDE OK", Common.Common.JournalEntryType.Information) Else m_log.Log("EDKB04: Validierung ENDE NOK", Common.Common.JournalEntryType.Error) End If End If Catch ex As Exception m_log.Log("EDKB04: Error Load: " & ex.Message, Common.Common.JournalEntryType.Error) result = False End Try Return result End Function #End Region #Region "Private Functions" Private Function IsValid(ByVal xmlImportFile As FileInfo) As Boolean Try 'First we create the xmltextreader Dim reader As New XmlTextReader(xmlImportFile.FullName) 'We pass the xmltextreader into the xmlvalidatingreader 'This will validate the xml doc with the schema file 'NOTE the xml file it self points to the schema file Dim validator As New XmlValidatingReader(reader) ' Set the validation event handler AddHandler validator.ValidationEventHandler, _ AddressOf ValidationCallback _validationSuccess = True 'make sure to reset the success var ' Read XML data While (validator.Read) End While 'Close the reader. validator.Close() reader.Close() 'The validationeventhandler is the only thing that would 'set m_Success to false Return _validationSuccess Catch ex As Exception _validationSuccess = False Return _validationSuccess 'Throw ex End Try End Function Private Function IsValid(ByVal strData As String) As Boolean Try 'First we create the xmltextreader Dim reader As New XmlTextReader(strData) 'We pass the xmltextreader into the xmlvalidatingreader 'This will validate the xml doc with the schema file 'NOTE the xml file it self points to the schema file Dim validator As New XmlValidatingReader(reader) ' Set the validation event handler AddHandler validator.ValidationEventHandler, _ AddressOf ValidationCallback _validationSuccess = True 'make sure to reset the success var ' Read XML data While (validator.Read) End While 'Close the reader. validator.Close() reader.Close() 'The validationeventhandler is the only thing that would 'set m_Success to false Return _validationSuccess Catch ex As Exception _validationSuccess = False Return _validationSuccess 'Throw ex End Try End Function Private Sub ValidationCallback(ByVal sender As Object, ByVal args As ValidationEventArgs) Try 'Display the validation error. This is only called on error _validationSuccess = False 'Validation failed m_log.Log("EDKB04: Validation error: " + args.Message + Environment.NewLine, Common.Common.JournalEntryType.Error) Catch ex As Exception Throw ex End Try End Sub #End Region End Module