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

Développement Windows Discussion :

vb.net avec XML


Sujet :

Développement Windows

  1. #1
    Membre confirmé
    Inscrit en
    Juin 2002
    Messages
    198
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 198
    Par défaut vb.net avec XML
    Bonjour,

    Je travail sur un petit programme utilisant un fichier XML contenant des informations sur des fluides.
    J'essaie d'utiliser le fichier XML directement sans intermédiaire type DataGridView. (Est-ce judicieux?)

    Je veux remplir des TextBoxes. Ça marche (presque) mais je me demande s'il est possible d'utiliser "lineNumber" pour aller directement 'a la ligne souhaitée et ainsi éviter le "select case.." ?

    Merci de votre aide!

    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    Private Sub UpdateProductProp(ByVal aProd As String)
            'show de property of a selected product
            Dim startLine As Integer = 0
            Dim aLine As Integer = 0
            Dim UpdateStart As Boolean = False
            Dim xmlDoc As New XmlTextReader(My.Settings.ProductBib)
     
            While (xmlDoc.Read() And aLine < 10) '10 = nb of prop
                Dim oType = xmlDoc.NodeType
                'check element
                If oType = XmlNodeType.Element And xmlDoc.Depth = 2 Then
                    If UpdateStart = True Then
                        aLine += 1
                        Select Case aLine
                            Case 1
                                TBoxIDSel.Text = xmlDoc.ReadInnerXml
                            Case 2
                                TBoxMindTSel.Text = xmlDoc.ReadInnerXml
                            Case 3
                                TBoxMaxdTSel.Text = xmlDoc.ReadInnerXml
                            Case 4
                                TBoxMaxIndHeatSel.Text = xmlDoc.ReadInnerXml
                            Case 5
                                TBoxMaxdirHeatSel.Text = xmlDoc.ReadInnerXml
                            Case 6
                                TBoxMaxBoilTSel.Text = xmlDoc.ReadInnerXml
                            Case 7
                                TBoxMinBoilTSel.Text = xmlDoc.ReadInnerXml
                            Case 8
                                TBoxMinProdTSel.Text = xmlDoc.ReadInnerXml
                            Case 9
                                TBoxMinProConSel.Text = xmlDoc.ReadInnerXml
                            Case 10
                                TBoxMaxProConSel.Text = xmlDoc.ReadInnerXml
                        End Select
     
                        Debug.Print(aLine)
                    End If
     
     
                    If xmlDoc.ReadInnerXml = aProd Then
                        UpdateStart = True
                    End If
                End If
            End While
     
            'TBoxIDSel.Text = xmlDoc.LineNumber(aLine + 1).readInnerXml '(xmlDoc.LineNumber(aLine + 1))
     
     
            xmlDoc.Close()
            xmlDoc = Nothing
     
        End Sub

    product.xml
    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
     
    <?xml version="1.0" standalone="yes"?>
    <Products>
      <Product>
        <Product_Name>cc</Product_Name>
        <Product_ID>2</Product_ID>
        <MindT_x00B0_C>2</MindT_x00B0_C>
        <MaxdT_x00B0_C>2</MaxdT_x00B0_C>
        <MaxIndHeatingT_x00B0_C>2</MaxIndHeatingT_x00B0_C>
        <MaxDirectHeatingT_x00B0_C>2</MaxDirectHeatingT_x00B0_C>
        <MaxBoilingT_x00B0_C>2</MaxBoilingT_x00B0_C>
        <MinBoilingT_x00B0_C>2</MinBoilingT_x00B0_C>
        <MinProductT_x00B0_C>2</MinProductT_x00B0_C>
        <MinProductConcentration_x0025_TS>2</MinProductConcentration_x0025_TS>
        <MaxProductConcentration_x0025_TS>2</MaxProductConcentration_x0025_TS>
      </Product>
      <Product>
        <Product_Name>dd</Product_Name>
        <Product_ID>3</Product_ID>
        <MindT_x00B0_C>3</MindT_x00B0_C>
        <MaxdT_x00B0_C>3</MaxdT_x00B0_C>
        <MaxIndHeatingT_x00B0_C>3</MaxIndHeatingT_x00B0_C>
        <MaxDirectHeatingT_x00B0_C>3</MaxDirectHeatingT_x00B0_C>
        <MaxBoilingT_x00B0_C>3</MaxBoilingT_x00B0_C>
        <MinBoilingT_x00B0_C>3</MinBoilingT_x00B0_C>
        <MinProductT_x00B0_C>3</MinProductT_x00B0_C>
        <MinProductConcentration_x0025_TS>3</MinProductConcentration_x0025_TS>
        <MaxProductConcentration_x0025_TS>3</MaxProductConcentration_x0025_TS>
      </Product>
    </Products>

  2. #2
    Membre confirmé
    Inscrit en
    Juin 2002
    Messages
    198
    Détails du profil
    Informations forums :
    Inscription : Juin 2002
    Messages : 198
    Par défaut
    J'ai changé le code et cette nouvelle version me semble parfaite


    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
     
       Private Sub UpdateProductProp(ByVal aProd As String)
     
            Dim xmlDoc As New XmlDocument()
            xmlDoc.Load(My.Settings.ProductBib)
            Dim nodes As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("/Products/Product")
     
            For Each node As XmlNode In nodes
                If node.SelectSingleNode("Product_Name").InnerText = aProd Then
                    TBoxIDSel.Text = node.SelectSingleNode("Product_ID").InnerText
                    TBoxMindTSel.Text = node.SelectSingleNode("MindT_x00B0_C").InnerText
                    TBoxMaxdTSel.Text = node.SelectSingleNode("MaxdT_x00B0_C").InnerText
                    TBoxMaxIndHeatSel.Text = node.SelectSingleNode("MaxIndHeatingT_x00B0_C").InnerText
                    TBoxMaxdirHeatSel.Text = node.SelectSingleNode("MaxDirectHeatingT_x00B0_C").InnerText
                    TBoxMaxBoilTSel.Text = node.SelectSingleNode("MaxBoilingT_x00B0_C").InnerText
                    TBoxMinBoilTSel.Text = node.SelectSingleNode("MinBoilingT_x00B0_C").InnerText
                    TBoxMinProdTSel.Text = node.SelectSingleNode("MinProductT_x00B0_C").InnerText
                    TBoxMinProConSel.Text = node.SelectSingleNode("MinProductConcentration_x0025_TS").InnerText
                    TBoxMaxProConSel.Text = node.SelectSingleNode("MaxProductConcentration_x0025_TS").InnerText
                End If
            Next
            xmlDoc = Nothing
     
        End Sub

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

Discussions similaires

  1. Communication Java et .net avec fichiers XML
    Par missyasmine dans le forum Format d'échange (XML, JSON...)
    Réponses: 0
    Dernier message: 10/08/2011, 14h53
  2. ASP.NET MVC avec XML
    Par peephole83 dans le forum ASP.NET MVC
    Réponses: 3
    Dernier message: 19/04/2010, 23h37
  3. [VB.net]Lecture xml vers dataset : prob avec sous noeuds
    Par Garrett dans le forum Windows Forms
    Réponses: 1
    Dernier message: 25/04/2007, 20h28
  4. Réponses: 6
    Dernier message: 21/07/2005, 16h56

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