Welcome Guest ( Log In | Register )


Bump Topic Add Reply RSS Feed New Topic New Poll

Outline · [ Standard ] · Linear+

> vb.net XML file, how to read from xml

views
     
TSWalaweiii
post Apr 10 2019, 06:12 AM, updated 2 months ago

New Member
*
Group: Newbie
Posts: 22

Joined: Jan 2019


this is my code snippet for write..no problem with it
For Each i As Integer In number
writer.WriteElementString("input" & (i), "10")
writer.WriteElementString("input2" & (i), "20")
writer.WriteElementString("input3" & (i), "30")
writer.WriteElementString("input4" & (i), "40")
writer.WriteElementString("input5" & (i), "50")
Next

the question is how to read the xml file using one node list and show it in their on textbox?

this is my read code so far

Dim nl As XmlNodeList = c.GetElementsByTagName("input")
...

For Each node As XmlNode In nl
textbox1.text(node.InnerText)
...
Next node

plus the textbox1.text show red underline..and i dont understand why.

btw this is my first time with xml.

This post has been edited by Walaweiii: Apr 10 2019, 06:14 AM
Eventless
post Apr 10 2019, 06:57 AM

Look at all my stars!!
*******
Group: Senior Member
Posts: 2,536

Joined: Jan 2003
QUOTE(Walaweiii @ Apr 10 2019, 06:12 AM)
CODE
           textbox1.text(node.InnerText)

plus the textbox1.text show red underline..and i dont understand why.
*
Assuming the code with the error is the line above, that is not how you assign a string to a textbox.
CODE
textbox1.text=node.Innertext


Another possible reason is that textbox1 doesn't exist.

If you mouse over the red underline, does a message pop up to indicate what the error is?
TSWalaweiii
post Apr 10 2019, 07:33 AM

New Member
*
Group: Newbie
Posts: 22

Joined: Jan 2019


QUOTE(Eventless @ Apr 10 2019, 06:57 AM)
Assuming the code with the error is the line above, that is not how you assign a string to a textbox.
CODE
textbox1.text=node.Innertext


Another possible reason is that textbox1 doesn't exist.

If you mouse over the red underline, does a message pop up to indicate what the error is?
*
is it like this?

txtbox1.Text = Text(node.InnerText)

no error shows.

but there is not output at the textbox
Eventless
post Apr 10 2019, 07:44 AM

Look at all my stars!!
*******
Group: Senior Member
Posts: 2,536

Joined: Jan 2003
QUOTE(Walaweiii @ Apr 10 2019, 07:33 AM)
is it like this?

txtbox1.Text = Text(node.InnerText)
*
Did you read my entire post? The corrected code was already there.
QUOTE(Walaweiii @ Apr 10 2019, 07:33 AM)
no error shows.

but there is not output at the textbox
*
Maybe your code isn't returning any value for the textbox to show?

Have your tried using a break point to see whether your program actualy reaches the line where your assign the value to your textbox.
https://docs.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2019
TSWalaweiii
post Apr 10 2019, 07:55 AM

New Member
*
Group: Newbie
Posts: 22

Joined: Jan 2019


QUOTE(Eventless @ Apr 10 2019, 07:44 AM)
Did you read my entire post? The corrected code was already there.

Maybe your code isn't returning any value for the textbox to show?

Have your tried using a break point to see whether your program actualy reaches the line where your assign the value to your textbox.
https://docs.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2019
*
ohh sorry..i mislook at ur code. haven't sleep yet.

i use the breakpoint at

For Each node As XmlNode In nl

and at

txtbox1.Text = node.InnerText

it shows

System.NullReferenceException: 'Object reference not set to an instance of an object.'

im not sure if i put the breakpoint at the right place coz i already sleepy af bangwall.gif
Eventless
post Apr 10 2019, 05:50 PM

Look at all my stars!!
*******
Group: Senior Member
Posts: 2,536

Joined: Jan 2003
QUOTE(Walaweiii @ Apr 10 2019, 07:55 AM)
ohh sorry..i mislook at ur code. haven't sleep yet.

i use the breakpoint at

For Each node As XmlNode In nl

and at

txtbox1.Text = node.InnerText

it shows

System.NullReferenceException: 'Object reference not set to an instance of an object.'

im not sure if i put the breakpoint at the right place coz i already sleepy af  bangwall.gif
*
That error indicates that your are trying to use an object that doesn't exists. Could be txtbox1 or node that is causing the problem.

Breakpoint is placed correctly. You want to place them at the place where you expect the error to happen or just before that. That way you can look at the content of the variables at that point in the program using the immediate window.
https://docs.microsoft.com/en-us/visualstudio/ide/reference/immediate-window?view=vs-2019

Moshpit94
post Apr 11 2019, 02:38 PM

Getting Started
**
Group: Junior Member
Posts: 203

Joined: Feb 2011
From: Earth
Create object and tada!


De-Serialize
CODE
Dim ser As XmlSerializer
       ser = New XmlSerializer(ObjType)
       Dim stringReader As StringReader
       stringReader = New StringReader(Xml)
       Dim xmlReader As XmlTextReader
       xmlReader = New XmlTextReader(stringReader)
       Dim obj As Object
       obj = ser.Deserialize(xmlReader)
       xmlReader.Close()
       stringReader.Close()
       Return obj



Serialize
CODE
Public Shared Function ToXElement(Of T)(ByVal graph As T) As XElement
       Using stream = New MemoryStream()
           ToXmlStream(stream, graph)
           stream.Position = 0

           Using reader = XmlReader.Create(stream)
               Dim e As XElement = XElement.Load(reader)
               Return XElement.Parse(e)
           End Using
       End Using




Bump Topic Add ReplyOptions New Topic
 

Switch to:
| Lo-Fi Version
0.0649sec    1.79    5 queries    GZIP Disabled
Time is now: 21st May 2019 - 07:19 PM