read xml

1. hi all im trying to get values from a simple xml document but im unsure of the best way so far i have
2. textReader.ReadToFollowing("invoice_number")
3. textReader.Read()
4. TextBox1.Text = (textReader.Value.ToString) textReader.ReadToFollowing("customer_title")
5. textReader.Read()
6. TextBox2.Text = (textReader.Value.ToString) textReader.ReadToFollowing("customer_firstname")
7. textReader.Read()
8. TextBox3.Text = (textReader.Value.ToString)
9. however after it has lopped through about ten it wont get any more values there must be a more efficient way. part of the xml document is formatted like this any help would be greatly appreaciated
10. - <job_sheet>
11. <invoice_number>25027</invoice_number>
12. <customer_title>Mr</customer_title>
13. <customer_firstname>t</customer_firstname> <customer_lastname>pearce</customer_lastname>
14. <customer_address>wrfg wrfg q</customer_address> <customer_postcode>erggerge</customer_postcode> <customer_telnumber>452435</customer_telnumber>
[1185 byte] By [ti_m] at [2007-12-24]
# 1

If it is an XML file then try using the methids in the System.XML namespace...specifically the xmlreader class instead of the textreader

The xmlReader class has methods for reading elements and attributes built into the class

DMan1 at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

Here's a simple example:

Imports System.Xml

Imports System.Text

Public Class Form1

Private sb As New StringBuilder

Private Count As Integer

Private Enum Items

Number

severity

End Enum

Private Sub ParseXML()

Dim Name As String = ""

Dim settings As New XmlReaderSettings

settings.IgnoreProcessingInstructions = True

settings.IgnoreComments = True

settings.ProhibitDtd = False

Dim r As XmlReader = XmlReader.Create("c:\temp\scan.xmlorg", settings)

r.ReadToFollowing("INFOS")

While r.Read()

If r.IsStartElement Then

Name = r.Name

Select Case Name

Case "INFO"

Parse(r, "Info")

Case "SERVICE"

Parse(r, "Service")

Case "VULN"

Parse(r, "Vulnerability")

End Select

End If

End While

r.Close()

TextBox1.Text = sb.ToString

Me.UseWaitCursor = False

End Sub

Private Sub Parse(ByRef r As XmlReader, ByVal Name As String)

Count += 1

sb.Append(Str(Count) + ".)" + vbTab + Name + " Number: " + r.Item(Items.Number) + vbTab + " Severity: " + r.Item(Items.severity) + vbCrLf)

r.ReadToFollowing("TITLE")

sb.Append(vbTab + "Title: " + r.ReadElementString + vbCrLf)

r.ReadToFollowing("RESULT")

End Sub

Private Sub cbGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbGo.Click

ParseXML()

End Sub

End Class

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...