Jump to content

I have this app for my incomes and outcomes and I saved everything in an XML file, how do I read from it and load all the stuff I saved.

 

Spoiler

|| Asrock Z68 Extreme 3 Gen 3 || i5 3570 @3.5GHz || Zalman CNPS10X Optima || 8GB RAM HyperX Fury Blue @ 1600MHz || Thermaltake Berlin 630W || Zalman Z11 || Gainward Phantom GTX 970 || 120GB Kingston V300  (Gift) + 1TB  WD Green

 

Phone: Xiaomi Redmi Note 8

Tablet: iPad Mini 2

Link to comment
https://linustechtips.com/topic/619781-reading-from-xml-visual-basic/
Share on other sites

Link to post
Share on other sites

Don't know too much about XML but if its just a normal XML file have you tried opening it in something like Notepad++, Visual Studio Code, Visual Studio? I know your header say Visual Basic but you haven't supplied a lot of information. 

Like if you liked it. Share it if you thought it was great. Leave a reply if you emotions are a bit more complicated   ¯\_(ツ)_/¯

Link to post
Share on other sites


Imports System.IO
Imports System
Imports System.Xml

Public Class Form1


    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub

    Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged


    End Sub

    Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label13.Text = TextBox5.Text + (TextBox8.Text - TextBox7.Text) + (TextBox3.Text - TextBox4.Text)

        Dim settings As New XmlWriterSettings()
        settings.Indent = True

        ' Initialize the XmlWriter.
        Dim XmlWrt As XmlWriter = XmlWriter.Create("MyName.xml", settings)

        With XmlWrt

            ' Write the Xml declaration.
            .WriteStartDocument()

            ' Write a comment.
            .WriteComment("XML Database.")

            ' Write the root element.
            .WriteStartElement("Data")

            ' Start our first person.
            .WriteStartElement("Dati")

            ' The person nodes.

            .WriteStartElement("Data1")
            .WriteString(TextBox1.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("Data2")
            .WriteString(TextBox10.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("Motivo1")
            .WriteString(TextBox2.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("Motivo2")
            .WriteString(TextBox9.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("Entrata1")
            .WriteString(TextBox3.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("Entrata2")
            .WriteString(TextBox8.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("Uscita1")
            .WriteString(TextBox4.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("Uscita2")
            .WriteString(TextBox7.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("BudgetIn")
            .WriteString(TextBox5.Text.ToString())
            .WriteEndElement()

            .WriteStartElement("SaldoFi")
            .WriteString(Label13.Text.ToString())
            .WriteEndElement()

            ' The end of this person.
            .WriteEndElement()

            ' Close the XmlTextWriter.
            .WriteEndDocument()
            .Close()

        End With
        MessageBox.Show("XML file saved.")

    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged


    End Sub

    Private Sub TextBox10_TextChanged(sender As Object, e As EventArgs) Handles TextBox10.TextChanged

    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub TextBox9_TextChanged(sender As Object, e As EventArgs) Handles TextBox9.TextChanged

    End Sub

    Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged

    End Sub

    Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged

    End Sub

    Private Sub Label13_Click(sender As Object, e As EventArgs) Handles Label13.Click


    End Sub

End Class


 

This is the code I've used, variables are in italian so it's normal if you don't understand them (Ex. Entrate, Uscite are variables), it also saves an XML file with the informations, which I have to load when I open it later so it fills the forms, this is the XML file:

 


<?xml version="1.0" encoding="utf-8"?>
<!--XML Database.-->
<Data>
  <Dati>
    <Data1>3/5/16</Data1>
    <Data2>9/5/16</Data2>
    <Motivo1>55</Motivo1>
    <Motivo2>5</Motivo2>
    <Entrata1>2</Entrata1>
    <Entrata2>4</Entrata2>
    <Uscita1>8</Uscita1>
    <Uscita2>9</Uscita2>
    <BudgetIn>120</BudgetIn>
    <SaldoFi>109</SaldoFi>
  </Dati>
</Data>

 

Spoiler

|| Asrock Z68 Extreme 3 Gen 3 || i5 3570 @3.5GHz || Zalman CNPS10X Optima || 8GB RAM HyperX Fury Blue @ 1600MHz || Thermaltake Berlin 630W || Zalman Z11 || Gainward Phantom GTX 970 || 120GB Kingston V300  (Gift) + 1TB  WD Green

 

Phone: Xiaomi Redmi Note 8

Tablet: iPad Mini 2

Link to post
Share on other sites

Here is a PDF from my university, this is from my web services unit but it covers using xml in visual basic.

 

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

22 hours ago, arvark said:

This is the code I've used, variables are in italian so it's normal if you don't understand them (Ex. Entrate, Uscite are variables), it also saves an XML file with the informations, which I have to load when I open it later so it fills the forms, this is the XML file:

Yes your code is indeed quite dire...

 

Have a read through Serialization and LINQ to XML (mentioned by @vorticalbox).

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×