By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Data from xml file gets truncated when writing to text file

P: n/a
sp
Hello everybody,

I have an xml doc and I am trying to write the values from xml file to a tab
delimited text file. Currently, what I am doing is I am reading xml file
through XpathNavigaotr and manipulating all the nodes,elements and attributes
than I am writing those values to a text file using stream writer. Now coming
to my problem When I am writing data to the text file value of the last
record is getting truncated. My code sample for formatting the xml looks like
this
Private Sub Format(ByVal myXPathNavigator As XPathNavigator)
Dim strtemp As String = String.Empty
If Not (myXPathNavigator.HasChildren) Then

If (myXPathNavigator.NodeType = XPathNodeType.Text) Then

' Console.Write(myXPathNavigator.Value + Chr(9))
strtemp = myXPathNavigator.Value
writer.Write(strtemp + Chr(9))
ElseIf (myXPathNavigator.Name <> String.Empty) Then
' Console.WriteLine("<" & myXPathNavigator.Name & ">")
Else
'Console.WriteLine()
End If

Else
'; Console.WriteLine("<" & myXPathNavigator.Name & ">")

' Show the attributes if there are any
If (myXPathNavigator.HasAttributes) Then
If (myXPathNavigator.MoveToFirstAttribute()) Then
strtemp = myXPathNavigator.Value
writer.Write(strtemp + Chr(9))

While (myXPathNavigator.MoveToNextAttribute())

'strtemp = fnRemoveKeyChars(myXPathNavigator.Value)
strtemp = myXPathNavigator.Value
writer.Write(strtemp + Chr(9))

End While

' Return to the 'Parent' node of the attributes
myXPathNavigator.MoveToParent()
End If
End If
End If
End Sub

Here writer is the streamwriter.
Any help is greatly appreciated.

Thanks
sp

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"sp" <sp@discussions.microsoft.com> wrote in message news:83**********************************@microsof t.com...
to my problem When I am writing data to the text file value of the last
record is getting truncated.


Where have you called Flush (and Close) on the StreamWriter, writer?

I don't see from the Sub you've furnished where / how you've opened
the StreamWriter, so perhaps you are calling Close outside of the Sub,
but if you're missing this call it's a likely cause for the stream to appear
incomplete.
Derek Harmon
Nov 12 '05 #2

P: n/a
sp
Mr. Harmon,

Thank you very much for taking time to look at my problem. Actually I
forgot to put those two statments in my program. Now, after using those
statements in my program its working fine.

Thankyou very much

regards
SP
"Derek Harmon" wrote:
"sp" <sp@discussions.microsoft.com> wrote in message news:83**********************************@microsof t.com...
to my problem When I am writing data to the text file value of the last
record is getting truncated.


Where have you called Flush (and Close) on the StreamWriter, writer?

I don't see from the Sub you've furnished where / how you've opened
the StreamWriter, so perhaps you are calling Close outside of the Sub,
but if you're missing this call it's a likely cause for the stream to appear
incomplete.
Derek Harmon

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.