vendredi 5 août 2011

read xm in c#

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Data;
 
namespace XPath
{
    class Program
    {
/* contenu du fichier xml test01.xml */
 
//<?xml version="1.0" encoding="utf-8" ?>
//<nodes>
// <node value="01" text="text1" chercher="mot1" />
// <node value="02" text="text2" chercher="mot2" />
// <node value="03" text="text3" chercher="mot3" />
// <node value="04" text="text4" chercher="mot4" />
// <node value="05" text="text5" chercher="mot5" />
// <node value="06" text="text6" chercher="mot6" />
//</nodes>
        static void Main(string[] args)
        {
            Console.WriteLine("start");
            XmlDocument monXml = new XmlDocument();
            XmlDocument maselection = new XmlDocument();
            try
            {
                monXml.Load("test01.xml");
                Console.WriteLine("XML Chargé");
            }
 
            catch (Exception ex)
            {
                Console.WriteLine("erreur {0}", ex.Message);
            }
           // maselection = monXml.SelectSingleNode("//BBB[@value='01']");
 
 
            XmlNode objNode;
            XmlNode root = monXml.DocumentElement;
 
            objNode = root.SelectSingleNode("//node[@value='03']");
 
            Console.WriteLine("{0},{1},{2}", (string)objNode.Attributes[0].InnerText.ToString(), (string)objNode.Attributes[1].InnerText.ToString(), (string)objNode.Attributes[2].InnerText.ToString());
 
            }
    }
}
 
 
 
http://www.b-integration.net/Articles/tabid/433/articleType/ArticleView/articleId/375/TUTO-C-Lire-un-XML.aspx

Aucun commentaire:

Enregistrer un commentaire

Nombre total de pages vues