Connaitre la ligne ou se trouve un XmlReader
Bonjour,
Dans le cadre de l'écriture d'un parser XML qui contrôle également les caractères autorisés dans mes fichiers, j'aimerai savoir comment récupérer les lignes ou se situent les erreurs (dans le callback et dans CheckChars ).
Pouvez vous m'aider j'ai pas trouvé sur la doc msdn de XmlReader
Cordialement,
Mckilleron
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Private Sub ValidateXml(ByVal xmlPath As String, ByVal xsdPath As String, ByVal xmlns As String)
Dim schemaSet As New XmlSchemaSet()
schemaSet.Add(xmlns, xsdPath)
Dim ReaderSettings As New XmlReaderSettings()
ReaderSettings.ValidationType = ValidationType.Schema
ReaderSettings.Schemas = schemaSet
AddHandler ReaderSettings.ValidationEventHandler, AddressOf ValidationCallBack
Dim xmlReader As XmlReader = xmlReader.Create(xmlPath, ReaderSettings)
While xmlReader.Read()
If Me.caracteresInterdits.Checked Then
If CheckChars(xmlReader.Value) = False And xmlReader.Value.Length > 0 Then
SetText("la chaine """ + xmlReader.Value + """contient des caractères interdits" + Chr(10))
End If
End If
End While
If Me.ResultTextBox.TextLength = 0 Then
SetText("Aucune Erreur de validation")
End If
SetTextLabelEtat("Etat : Prêt")
End Sub
Private Sub ValidationCallBack(ByVal sender As Object, ByVal e As ValidationEventArgs)
SetText("Erreur de validation" + e.Message + Chr(10))
End Sub
Function CheckChars(ByVal chaine As String)
Dim myRegex = New Regex("^(?:\w|\d|[""&'+_-]|[\(\)\,\.\/\\\<\>;\:\s\=\?\@])+$", RegexOptions.IgnoreCase)
Return myRegex.IsMatch(chaine)
End Function |