I'm using XmlNodeReader

mH_p0rtal

Well-known member
Joined
Oct 17, 2006
Messages
61
Location
Persia
Programming Experience
3-5
i want explain about XML & how to read xml file in vb.net
first our xml file example
<?xml version="1.0" ?>
- <article>
<title>irane man</title>

<date>1386 / 10 / 18</date>

<contain>salam be baro bachz</contain>

- <!-- mH_p0rtal -->f(clean);
</article>
after that we must imports xml to our project
define a variable for xml document & import the xml file on it .
& also define a variable for reading it & relate xml doc variable to it .
& with a while & case for assigne which element want be display
i use than Richtextbox in this project & use some command for deface it to another color , you can develop it

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rerr As DialogResult = OpenFileDialog1.ShowDialog()
If rerr = DialogResult.Cancel Then
Return
End If
Dim lfx As XmlDocument = New XmlDocument
lfx.Load(OpenFileDialog1.FileName)
Dim reader As XmlNodeReader = New XmlNodeReader(lfx)
While reader.Read

Select Case reader.NodeType
Case XmlNodeType.Element
TextBox1.Text &= "<" & reader.Name & ">" & vbCrLf
Case XmlNodeType.Comment
TextBox1.Text &= "<!--" & reader.Value & "-->"
Case XmlNodeType.Text
TextBox1.Text &= reader.Value & vbCrLf

Case XmlNodeType.XmlDeclaration
TextBox1.Text &= "<?" & reader.Name & " " & reader.Value & "?>" & vbCrLf
Case XmlNodeType.EndElement
TextBox1.Text &= "</" & reader.Name & ">" & vbCrLf

End Select
End While


TextBox1.SelectionStart = TextBox1.Find("<!--")
TextBox1.SelectionColor = Color.Gray
TextBox1.SelectionStart = TextBox1.Find("-->")
TextBox1.SelectionColor = Color.Gray
TextBox1.SelectionStart = TextBox1.Find("<?XML")
TextBox1.SelectionColor = Color.Blue
TextBox1.SelectionStart = TextBox1.Find("?>")
TextBox1.SelectionColor = Color.Blue

End Sub
 
Back
Top