Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

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

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
{
    ///
<summary>
    /// Une méthode supplémentaire pour traiter les documents XML.
    /// </summary>
 
    public static class XmlExt
    {
 
        ///
<summary>
        /// Gets a string from an attribute or noeud.
        /// </summary>
 
        ///
<param nom="noeud"></param>
        ///
<param nom="nom"></param>
        ///
<param nom="valDefaut"></param>
        /// <returns></returns>
        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;
        }
 
    }
 
}

No comments yet.

Leave a Comment