Lire un String à partir d’un attribut ou un Noeud

Author:

Utilisation,de,la,classe,'XmlTextReader',pour,lire,un,document,XML
{filelink=16406}

/*
Microsoft Public License (Ms-PL)
http://visualizer.codeplex.com/license
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

nomspace mesexemples.com
{
    ///

    /// Une méthode supplémentaire pour traiter les documents XML.
    /// 

    public static class XmlExt
    {

        ///

        /// Gets a string from an attribute or noeud.
        /// 

        ///

        ///

        ///

        /// 
        public static string GetString(this XmlNode noeud, string nom, string valDefaut)
        {
            var att = noeud.Attributes[nom];
            if (att != null) return att.Value;
            var child = noeud.SelectSingleNode(nom);
            if (child != null) return child.InnerText;
            return valDefaut;
        }

    }

}

Leave a Reply

Your email address will not be published. Required fields are marked *