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

XmlTextWriter: Why is endElement not written using the WriteEndElement with WriteRaw

P: n/a
Can somebody explain why the endElement (</items>) in the following sample
is not written?

Public Sub Test()
Dim objMem As New MemoryStream
Dim objWriter As New XmlTextWriter(objMem, New
System.Text.ASCIIEncoding)
Dim strXMLResult As String
objWriter.WriteStartDocument()
objWriter.WriteStartElement("items")
objWriter.WriteRaw(GetItem(1))
objWriter.WriteEndElement() 'Why is this endElement not writen?
objWriter.WriteEndDocument()
objWriter.Flush()
objWriter.Close()
strXMLResult =
System.Text.Encoding.UTF8.GetString(objMem.GetBuff er())

'strXMLReult will contain the string (without the end </items>)
Why?:
'<?xml version="1.0" encoding="utf-8"?><items><Item
number="1"><Value>just a value</Value></Item>
End Sub

Private Function GetItem(ByVal number As Integer) As String
Dim objMem As New MemoryStream
Dim objWriter As New XmlTextWriter(objMem, New
System.Text.ASCIIEncoding)
Dim strXMLResult As String

objWriter.WriteStartElement("Item")
objWriter.WriteAttributeString("number", number.ToString)
objWriter.WriteElementString("Value", "just a value")
objWriter.WriteEndElement()
objWriter.Flush()
objWriter.Close()

strXMLResult =
System.Text.Encoding.UTF8.GetString(objMem.GetBuff er())
objMem.Close()
Return strXMLResult
End Function
Nov 11 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Solved the problem myself,

must use
System.Text.Encoding.UTF8.GetString(objMem.GetBuff er(), 0, objMem.Length)

instead of
System.Text.Encoding.UTF8.GetString(objMem.GetBuff er())
Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.