Mar 5, 2010 05:39 AM
(This post was last modified: Jan 8, 2011 04:35 PM by You Are Free.)
IMAGES DOWN! This is an old tutorial of mine, I need to find my original screenshots or make some new ones.
Before I begin, this is a tutorial on how to create an XML parser for you program.
XML can be used in many ways, in this example I will show you how to create an XML parser that will read from an XML file for a "news" form.
Before we begin, make sure you have these imported:
Now put together your interface, make sure you have at least 3 read only text boxes and 1 button, make one textbox "authorfield", make another one "datefield", and the last one "newsfield".
Place them where you want, you can guess where they go.. :P
("newsfield" needs to be multiline)
I set mine together like this:
My interface (Click to View)
The button can be named anything, but in my case I named it "getnews".
Now double click the button, and place the imports I showed you above at the top, it should look like this:
Screenshot (Click to View)
Now add the following code in between the button's onclicked code:
In this example I am getting the XML file "newsdata.xml" from the application startup directory, you can get the XML file from anywhere.
Before I get started with the major coding, you need to make the XML file to parse.
Here it is:
Save that as a .xml file.
So basically, our parser will read the data in between the "author" field and show it, read the data in between the "date" field and show it, and then read the data in between the "content" field.
Now add:
From there on, make sure there are no errors.
It should look like:
Screenshot (Click to View)
Now tell you application to "build", save you XML file, place the XML file with the application.
Now run you application and press the button you made with it!
It should read from the XML file and bring back the details you gave it.
Make sure the XML file isn't blank!
A screenshot of the result:
Screeshot of running application (Click to View)
I used the XML code:
To get that result.
Have fun messing around with this!
The source is here:
Url down, please wait for me to find it on my end.
Before I begin, this is a tutorial on how to create an XML parser for you program.
XML can be used in many ways, in this example I will show you how to create an XML parser that will read from an XML file for a "news" form.
Before we begin, make sure you have these imported:
Code
Imports System.IO
Imports System.XmlNow put together your interface, make sure you have at least 3 read only text boxes and 1 button, make one textbox "authorfield", make another one "datefield", and the last one "newsfield".
Place them where you want, you can guess where they go.. :P
("newsfield" needs to be multiline)
I set mine together like this:
My interface (Click to View)
The button can be named anything, but in my case I named it "getnews".
Now double click the button, and place the imports I showed you above at the top, it should look like this:
Screenshot (Click to View)
Now add the following code in between the button's onclicked code:
Code
Dim m_xmlr As XmlTextReader
m_xmlr = New XmlTextReader(Application.StartupPath & "\newsdata.xml")
m_xmlr.WhitespaceHandling = WhitespaceHandling.NoneIn this example I am getting the XML file "newsdata.xml" from the application startup directory, you can get the XML file from anywhere.
Before I get started with the major coding, you need to make the XML file to parse.
Here it is:
Code
<XML>
<author></author>
<date></date>
<content></content>
</XML>So basically, our parser will read the data in between the "author" field and show it, read the data in between the "date" field and show it, and then read the data in between the "content" field.
Now add:
Code
m_xmlr.Read()
m_xmlr.Read()
Dim authorvalue = m_xmlr.ReadElementString("author")
Dim datevalue = m_xmlr.ReadElementString("date")
Dim contentvalue = m_xmlr.ReadElementString("content")
authorfield.Text = authorvalue
datefield.Text = datevalue
newsfield.Text = contentvalue
m_xmlr.Close()From there on, make sure there are no errors.
It should look like:
Screenshot (Click to View)
Now tell you application to "build", save you XML file, place the XML file with the application.
Now run you application and press the button you made with it!
It should read from the XML file and bring back the details you gave it.
Make sure the XML file isn't blank!
A screenshot of the result:
Screeshot of running application (Click to View)
I used the XML code:
Code
<XML>
<author>tannerzion</author>
<date>3/5/2010</date>
<content>Hello there peepz!</content>
</XML>To get that result.
Have fun messing around with this!
The source is here:
Url down, please wait for me to find it on my end.
![[Image: etRrWjZ.png]](https://i.imgur.com/etRrWjZ.png)

