Labels text = xml value?
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
9 posts
Page 1 of 1
Say an xml file has
Code: Select all
how could i have whats inside the "<txt>" tag show up as the label's text<!-- Example Xml i made for example -->
<!-- Thanks in advance -->
<txt>Get the newest Update: http://EXAMPLE.com/update.zip</txt>
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

You could use this:
Code: Select all
Dim xtr As XmlTextReader = New XmlTextReader("file.xml")
Dim content As String = xtr.ReadElementString("txt")
xtr.Close()
Label1.Text = content
Mandai, You should write a book on this 

Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

You've got me interested now, Zach :P
Hey Mandai, what if there is more than one txt tag?
Hey Mandai, what if there is more than one txt tag?
GoodGuy17 wrote:You've got me interested now, Zach :PWe'll im pretty sure you would need a timer and it would go back and forth between them
Hey Mandai, what if there is more than one txt tag?
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

You don't need a timer when the data stays the same.
In XML you aren't supposed to have root elements with the same name, but you could check for child txt nodes with this:
In XML you aren't supposed to have root elements with the same name, but you could check for child txt nodes with this:
Code: Select all
Dim xtr As XmlTextReader = New XmlTextReader("file.xml")
While xtr.Read()
If xtr.Name = "txt" Then
Dim content As String = xtr.ReadString()
MsgBox(content)
End If
End While
xtr.Close()
mandai wrote:You don't need a timer when the data stays the same.What do u mean by child?
In XML you aren't supposed to have root elements with the same name, but you could check for child txt nodes with this:Code: Select allDim xtr As XmlTextReader = New XmlTextReader("file.xml") While xtr.Read() If xtr.Name = "txt" Then Dim content As String = xtr.ReadString() MsgBox(content) End If End While xtr.Close()
like this?
Code: Select all
do u mean that?<txt>hi</txt>
<txt>hello</txt
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

It just means the txt elements are at least 1 level inside another element.
Like:
Like:
Code: Select all
<xml>
<txt>value1</txt>
<txt>value2</txt>
</xml>
I have always used a code like this to read xml file.
Not sure if it is more confusing to you or not.
The XML File
this code will loop through all the parent nodes "<user> ... </user>" and list all the entrys that it can find.
I use alot. It is just somthing that I am use to using.
I like using XML in my projects. Im not as good as using XML as I would like. But everytime I work with it in VB I do learn something new.
Not sure if it is more confusing to you or not.
The XML File
Code: Select all
The reader Code<xml>
<user>
<userid>1</userid>
<first>First Name</first>
<last>Last Name</last>
<email>myEmail@somesite.com</email>
</user>
<user>
<userid>2</userid>
<first>First Name</first>
<last>Last Name</last>
<email>myEmail@somesite.com</email>
</user>
</xml>
this code will loop through all the parent nodes "<user> ... </user>" and list all the entrys that it can find.
Code: Select all
I am still working on how to Edit, Remove an xml node in the example above. Try
Dim XmlDoc As New XmlDocument
'Location of Stored XMLfile and filename
XmlDoc.Load("C:\AppFile.xml") 'Path to XML file
For Each IDNode As XmlNode In XmlDoc.SelectNodes("//user")
If IDNode.HasChildNodes = True Then
txtFirstName.Text = IDNode.ChildNodes(0).InnerText '<userid></userid>
txtFirstName.Text = IDNode.ChildNodes(1).InnerText '<first></first>
txtLastName.Text = IDNode.ChildNodes(2).InnerText '<last></last>
txtEmail.Text = IDNode.ChildNodes(3).InnerText '<email></email>
End If
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
I use alot. It is just somthing that I am use to using.
I like using XML in my projects. Im not as good as using XML as I would like. But everytime I work with it in VB I do learn something new.
9 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023