Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2012
    Messaggi
    39

    [vb net 2010 express] leggere un file xml

    Salve io ho scritto un po' codice che mi permette di leggere un file xml, ma non funzia
    codice:
    Dim reader As XmlTextReader = New XmlTextReader(GetCurrentDirectory() & "\dati\elementi.xml") 
    Dim stringa, stringa2 As String 
    Dim cs As Boolean = False 
    Try 
    
    Do While (reader.Read()) 
    Select Case reader.NodeType 
    Case XmlNodeType.Element
     ' fino a qui funzia 
        If reader.HasAttributes = True Then
          If attributes exist reader.MoveToFirstAttribute() 
    stringa = reader.Name.ToString 
    stringa2 = reader.Value.ToString 
    MsgBox(stringa & vbCrLf & stringa2) 
          While reader.MoveToNextAttribute() 
    stringa = reader.Name.ToString 
    stringa2 = reader.Value.ToString 
    MsgBox(stringa & vbCrLf & stringa2) 
       If stringa = "carattere" Then 
    lblfont.Text = stringa2 
       End If 
      If stringa = "grandezzafont" Then 
    lbgrandezza.SelectedItem = stringa2 
       End If 
         If stringa = "grassetto" Then 
    If (stringa2 = "true" Or stringa2 = "1") Then
     CBbold.Checked = True 
    Else CBbold.Checked = False 
    End If
       End If 
      If stringa = "italico" Then 
    If (stringa2 = "true" Or stringa2 = "1") Then 
    CBitalic.Checked = True 
    Else CBitalic.Checked = False 
    End If 
       End If 
       If stringa = "cambiamenti" Then 
    If (stringa2 = "true" Or stringa2 = "1") Then 
    RBCsi.Checked = True 
    Else 
    RBCno.Checked = True 
    End If
        End If 
       If stringa = "accapo" Then 
    If (stringa2 = "true" Or stringa2 = "1") Then 
    RBaccaposi.Checked = True 
    Else 
    RBaccapono.Checked = True 
    End If 
        End If 
    If stringa = "salvataggio" Then 
    --------
    --------
    --------
       End If 
        End If 
          End If 
    End While 
    End Select 
    Loop 
    reader.Close() 
    Return True 
    Catch ex As Exception 
    MsgBox("Errore [112] " & ex.Message) 
    reader.Close() 
    Return False 
    End Try 
    reader.Close()
    potete provare a farlo funzionare?

    Grazie Molto

  2. #2
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802
    Non avendo la sfera di cristallo, cosa significa "non funziona"?
    Non compila? --> riporta gli errori di compilazione
    Compila ma da eccezione in esecuzione? --> riporta lo stack trace dell'eccezione
    Compila, viene eseguito, ma non fa quello che ti aspetti? --> spiega cosa ottieni e cosa vorresti ottenere
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2012
    Messaggi
    39
    No non fà nulla e non dà nessun errore, solo non legge niente.

  4. #4
    Utente di HTML.it L'avatar di gibra
    Registrato dal
    Apr 2008
    residenza
    Italy
    Messaggi
    4,244
    Originariamente inviato da libraio
    No non fà nulla e non dà nessun errore, solo non legge niente.
    Quindi devi prima fare un po' di DEBUG, riga per riga, e controllare il risultato dei comandi.

    Debug in Visual Studio
    http://msdn.microsoft.com/it-it/libr...(v=vs.90).aspx

    Seleziona la tua versione di Visual Studio, ovviamente.


  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2012
    Messaggi
    39
    Ho provato a seguire il tuo consiglio, ma mi sono perso... Allora ho cercato in un altro forum un equivalente a quello che cercavo :
    codice:
    Dim contatore As Integer 
    Dim XMLDoc As New Xml.XmlDocument XMLDoc.Load(GetCurrentDirectory() & "\dati\elementi.xml") 'xml file you want to load 
    Dim node As Xml.XmlNode = XMLDoc.SelectSingleNode("/datiopzioni/record") 'node path 
    Dim Path As String 
    Dim i As Integer = 0 
    For i = 0 To node.ChildNodes.Count - 1 Step 1 
    Path = node.ChildNodes(i).InnerText contatore = contatore + 1 Select 
    Case contatore 
    Case 1 
    If lbgrandezza.Items.Contains(Path).Equals(1) = True Then 
    Labelnum.Text = "1" 
    End If 
    Case 2 
    If lbgrandezza.Items.Contains(Path).Equals(3) = True Then 
    Labelnum.Text = "3" 
    End If 
    If lbgrandezza.Items.Contains(Path).Equals(5) = True Then 
    Labelnum.Text = "5" 
    End If 
    ---------
    ---------
    Ora mi torna tranne che il tipo di codifica per un oggetto del tipo :

    codice:
    If lbgrandezza.Items.Contains(Path).Equals(3) = True Then 
    Labelnum.Text = "3" 
    End If
    non succede nulla... scusate se passo la mano.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.