Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with XmlTextReader

Status
Not open for further replies.

pcsmurf

IS-IT--Management
Apr 26, 2002
47
0
0
GB
I have a script which reads through an XML file and writes out each article element to a separate file. Generally, this all works well but when the reader hits an HTML entity such as € it just skips this completly and carries on with the rest of the article.

Is there a switch or something I need to let it print the € into the file ?

The code in question is as follows:

Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'Start element.
If (reader.Name = "article") Then
' Start a new article file
writer = New XmlTextWriter(DIR_NAME & "article" + _
artcount.ToString + ".xml", _
System.Text.Encoding.UTF8)
' Set the formatting to something nice
writer.Formatting = Formatting.Indented
TextBox1.Text = TextBox1.Text & vbCrLf & _
"*** Writing Article " & artcount.ToString + ".xml"
TextBox1.Refresh()
End If
If (reader.Name = "publication") Then
TextBox1.Text = TextBox1.Text & vbCrLf & _
"*** Creating Publication Articles "
TextBox1.Refresh()
Else
writer.WriteStartElement(reader.Name)
If reader.HasAttributes Then
'If attributes exist
While reader.MoveToNextAttribute()
'Attribute name and value.
writer.WriteAttributeString _
(reader.Name, reader.Value)
End While
End If

End If
Case XmlNodeType.Text 'Display the text in each element.
MsgBox(reader.Value)
writer.WriteString(reader.Value)
Case XmlNodeType.EndElement 'End of element.
If (reader.Name = "publication") Then
TextBox1.Text = TextBox1.Text & vbCrLf & "*** END ****"
TextBox1.Refresh()
Else
writer.WriteFullEndElement()
End If
If (reader.Name = "article") Then
' Close article file
writer.Close()
artcount = artcount + 1
End If
End Select
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top