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

C# Discussion :

rechercher Last name avec c# au fichier XML [Débutant]


Sujet :

C#

  1. #1
    Membre du Club
    Inscrit en
    Octobre 2009
    Messages
    95
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Octobre 2009
    Messages : 95
    Points : 57
    Points
    57
    Par défaut rechercher Last name avec c# au fichier XML
    Bonjour, je debute en C# et xml...j'essaie de trouver un moyen de lire mon fichier xml et d'acceder a la bonne donnee. Ex: voici mon fichier XML
    Code xml : 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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    <?xml version="1.0" standalone="yes"?>
    <ContactDataSet xmlns="http://tempuri.org/ContactDataSet1.xsd">
      <xs:schema id="ContactDataSet" targetNamespace="http://tempuri.org/ContactDataSet1.xsd" xmlns:mstns="http://tempuri.org/ContactDataSet1.xsd" xmlns="http://tempuri.org/ContactDataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
        <xs:element name="ContactDataSet" msdata:IsDataSet="true" msdata:Locale="en-US">
          <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
              <xs:element name="Contact">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="ContactID" type="xs:string" minOccurs="0" />
                    <xs:element name="NameStyle" type="xs:string" minOccurs="0" />
                    <xs:element name="Title" type="xs:string" minOccurs="0" />
                    <xs:element name="FirstName" type="xs:string" minOccurs="0" />
                    <xs:element name="MiddleName" type="xs:string" minOccurs="0" />
                    <xs:element name="LastName" type="xs:string" minOccurs="0" />
                    <xs:element name="Suffix" type="xs:string" minOccurs="0" />
                    <xs:element name="EmailAddress" type="xs:string" minOccurs="0" />
                    <xs:element name="EmailPromotion" type="xs:string" minOccurs="0" />
                    <xs:element name="Phone" type="xs:string" minOccurs="0" />
                    <xs:element name="PasswordHash" type="xs:string" minOccurs="0" />
                    <xs:element name="PasswordSalt" type="xs:string" minOccurs="0" />
                    <xs:element name="AdditionalContactInfo" type="xs:string" minOccurs="0" />
                    <xs:element name="rowguid" type="xs:string" minOccurs="0" />
                    <xs:element name="ModifiedDate" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:choice>
          </xs:complexType>
        </xs:element>
      </xs:schema>
      <Contact>
        <ContactID>1</ContactID>
        <NameStyle>false</NameStyle>
        <Title>Mr.</Title>
        <FirstName>Michel</FirstName>
        <LastName>Bakary</LastName>
        <EmailAddress>gustavo0@adventure-works.com</EmailAddress>
        <EmailPromotion>2</EmailPromotion>
        <Phone>398-555-0132</Phone>
        <PasswordHash>GylyRwiKnyNPKbC1r4FSqA5YN9shIgsNik5ADyqStZc=</PasswordHash>
        <PasswordSalt>TVGHbhY=</PasswordSalt>
        <AdditionalContactInfo>&lt;AdditionalContactInfo xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo" xmlns:crm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactRecord" xmlns:act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"&gt;&lt;act:telephoneNumber&gt;&lt;act:number&gt;425-555-1112&lt;/act:number&gt;&lt;act:SpecialInstructions&gt;Call only after 5:00 p.m.&lt;/act:SpecialInstructions&gt;&lt;/act:telephoneNumber&gt;Note that the customer has a secondary home address.&lt;act:homePostalAddress&gt;&lt;act:Street&gt;123 Oak&lt;/act:Street&gt;&lt;act:City&gt;Seattle&lt;/act:City&gt;&lt;act:StateProvince&gt;WA&lt;/act:StateProvince&gt;&lt;act:PostalCode&gt;98001&lt;/act:PostalCode&gt;&lt;act:CountryRegion&gt;USA&lt;/act:CountryRegion&gt;&lt;act:SpecialInstructions&gt;If correspondence to the primary address fails, try this one.&lt;/act:SpecialInstructions&gt;&lt;/act:homePostalAddress&gt;Customer provided additional email address.&lt;act:eMail&gt;&lt;act:eMailAddress&gt;customer1@sample.com&lt;/act:eMailAddress&gt;&lt;act:SpecialInstructions&gt;For urgent issues, do not send e-mail. Instead use this emergency contact phone&lt;act:telephoneNumber&gt;&lt;act:number&gt;425-555-1111&lt;/act:number&gt;&lt;/act:telephoneNumber&gt;.&lt;/act:SpecialInstructions&gt;&lt;/act:eMail&gt;&lt;crm:ContactRecord date="2001-06-02Z"&gt;This customer is interested in purchasing high-end bicycles for his family. The customer contacted Michael in sales.&lt;/crm:ContactRecord&gt;&lt;/AdditionalContactInfo&gt;</AdditionalContactInfo>
        <rowguid>d4c132d3-fcb5-4231-9dd5-888a54bec693</rowguid>
        <ModifiedDate>2005-05-16T16:33:33.06+02:00</ModifiedDate>
      </Contact>
      <Contact>
        <ContactID>2</ContactID>
        <NameStyle>false</NameStyle>
        <Title>Ms.</Title>
        <FirstName>Catherine</FirstName>
        <MiddleName>R.</MiddleName>
        <LastName>Abel</LastName>
        <EmailAddress>catherine0@adventure-works.com</EmailAddress>
        <EmailPromotion>1</EmailPromotion>
        <Phone>747-555-0171</Phone>
        <PasswordHash>zh3goJUbYsPv92k4bVZuJtlLHwuvpQtu6uNcjkKSdF8=</PasswordHash>
        <PasswordSalt>rpyd5Tw=</PasswordSalt>
        <AdditionalContactInfo>&lt;AdditionalContactInfo xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo" xmlns:crm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactRecord" xmlns:act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"&gt;These are additional phone and pager numbers for the customer.&lt;act:telephoneNumber&gt;&lt;act:number&gt;206-555-2222&lt;/act:number&gt;&lt;act:SpecialInstructions&gt;On weekends, contact the manager at this number.&lt;/act:SpecialInstructions&gt;&lt;/act:telephoneNumber&gt;&lt;act:telephoneNumber&gt;&lt;act:number&gt;206-555-1234&lt;/act:number&gt;&lt;/act:telephoneNumber&gt;&lt;act:pager&gt;&lt;act:number&gt;206-555-1244&lt;/act:number&gt;&lt;act:SpecialInstructions&gt;Do not page between 9:00 a.m. and 5:00 p.m.&lt;/act:SpecialInstructions&gt;&lt;/act:pager&gt;Customer provided this additional home address.&lt;act:homePostalAddress&gt;&lt;act:Street&gt;P.O Box 5&lt;/act:Street&gt;&lt;act:City&gt;Edmonds&lt;/act:City&gt;&lt;act:StateProvince&gt;WA&lt;/act:StateProvince&gt;&lt;act:PostalCode&gt;98431&lt;/act:PostalCode&gt;&lt;act:CountryRegion&gt;USA&lt;/act:CountryRegion&gt;&lt;act:SpecialInstructions&gt;This is an alternative address for billing only.&lt;/act:SpecialInstructions&gt;&lt;/act:homePostalAddress&gt;&lt;act:eMail&gt;&lt;act:eMailAddress&gt;Joe@sample.com&lt;/act:eMailAddress&gt;&lt;act:SpecialInstructions&gt;Do not send e-mail for urgent issues. Use telephone instead.&lt;/act:SpecialInstructions&gt;&lt;/act:eMail&gt;&lt;crm:ContactRecord date="2001-07-02Z"&gt;Sales contacted this customer to explain new pricing.&lt;/crm:ContactRecord&gt;&lt;/AdditionalContactInfo&gt;</AdditionalContactInfo>
        <rowguid>d54e0552-c226-4c22-af3b-762ca854cdd3</rowguid>
        <ModifiedDate>2005-05-16T16:33:33.077+02:00</ModifiedDate>
      </Contact>
    j'aimerai entrer un txtRechercher.Text qui est FirstNameet et affiche FirstName et et LastName dans un gridview s'il existe sinon un message qui s'affiche qu'il n'existz pas
    et je n'ai aucune idee de comment faire je ne sais pas quoi utiliser entre XmlDocument, dataSet, xmlReader...
    et merci d'avance

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    122
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 122
    Points : 78
    Points
    78
    Par défaut
    Bonjour,

    Déjà pour lire ton fichier xml, les liens ci-après pourront peut-être t'aider :

    * Lire un fichier Xml
    * DotNet et Xml

    Salutations.

  3. #3
    Membre du Club
    Inscrit en
    Octobre 2009
    Messages
    95
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Octobre 2009
    Messages : 95
    Points : 57
    Points
    57
    Par défaut resolu
    merci beaucoup le probleme est resolu

    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
    private void button1_Click(object sender, EventArgs e)
            {
     
                try
                {
                    bool recherche =false ;
                    XmlTextReader reader = new XmlTextReader("ContactDetails.xml");
                    while (reader.Read())
                    {
                        if (reader.Value == txtRechercher.Text)
                        {
                            MessageBox.Show("l'element trouver");
                            recherche = true;
     
                            listBox1.Items.Add(reader);
                        }
                    }
                    if (recherche == false)
                        MessageBox.Show("l'element est introuvable"); 
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message,"Exception");
     
                }
     
     
     
            }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 07/09/2009, 07h15
  2. Connexion avec Mysql ou fichier XML
    Par namstou3 dans le forum Flex
    Réponses: 1
    Dernier message: 20/05/2008, 13h54
  3. [JDOM] Recherche d'un noeud dans un fichier XML
    Par pracede2005 dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 15/02/2008, 14h20
  4. Tableau avec une liaison fichier xml
    Par loizic dans le forum InfoPath
    Réponses: 1
    Dernier message: 25/04/2007, 08h21
  5. [C#][xml][regexp] Recherche d'une regexp dans un fichier xml
    Par LeJocker dans le forum Windows Forms
    Réponses: 4
    Dernier message: 18/10/2005, 12h29

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