IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

[2.0] Valider un fichier xml/xsd


Sujet :

ASP.NET

  1. #1
    Membre habitué
    Inscrit en
    Novembre 2004
    Messages
    469
    Détails du profil
    Informations forums :
    Inscription : Novembre 2004
    Messages : 469
    Points : 167
    Points
    167
    Par défaut [2.0] Valider un fichier xml/xsd
    bonjour à tous,

    j'ai créé un flux xml et j'aimerais valider ce flux par rapport à un fichier xsd.

    Existe t-il un moyen de réaliser ceci ?

    XmlValidator répond t-il à cettte problématique ?

    merci à tous

  2. #2
    maa
    maa est déconnecté
    Membre actif
    Avatar de maa
    Inscrit en
    Octobre 2005
    Messages
    672
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Octobre 2005
    Messages : 672
    Points : 288
    Points
    288
    Par défaut
    Tu peux utiliser un code qui ressemble à ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
            private bool validationSuccess;
            private List<string> errorsInXml;
            private XmlReaderSettings settings = new XmlReaderSettings();
     
            private bool validateXML(string path)
            {
                validationSuccess = true;
                errorsInXml = new List<string>();
                try
                {
                    settings.Schemas.Add(null, "../../CheckXml.xsd");
                    settings.ValidationType = ValidationType.Schema;
                    settings.ConformanceLevel = ConformanceLevel.Auto;
                    settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
                    XmlReader URI_XMlreader = XmlReader.Create(path, settings);
                    while (URI_XMlreader.Read()) { }
                }
                catch
                {
                    return false;
                }
                return validationSuccess;
            }
     
            private void ValidationCallBack(object sender, ValidationEventArgs args)
            {
                validationSuccess = false;
                errorsInXml.Add(args.Message);
                   XmlSchemaException ex = args.Exception;
                string message = string.Format(ex.Message + Environment.NewLine + "Ligne n° " + ex.LineNumber);
                MessageBox.Show(message);
            }

  3. #3
    Membre habitué
    Inscrit en
    Novembre 2004
    Messages
    469
    Détails du profil
    Informations forums :
    Inscription : Novembre 2004
    Messages : 469
    Points : 167
    Points
    167
    Par défaut
    merci pour ta réponse je vais tester tout ceci (y)

Discussions similaires

  1. validation fichier XML /XSD
    Par ammah dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 04/06/2009, 15h59
  2. valider un fichier xml par un xsd
    Par TaymouWan dans le forum C#
    Réponses: 4
    Dernier message: 25/03/2009, 11h36
  3. [XSD]Valider un fichier XML et son schéma
    Par _Fabien dans le forum Valider
    Réponses: 6
    Dernier message: 20/03/2007, 10h28
  4. [XSD] Valider un fichier XML via XSD
    Par laury33 dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 05/03/2007, 16h46
  5. [Xml/Xsd]valider son fichier Xml avec un schéma xsd
    Par ePoX dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 09/02/2006, 22h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo