469,609 Members | 1,831 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

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

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
1 3394
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.

Similar topics

1 post views Thread by Lee Atkinson | last post: by
3 posts views Thread by K Rege | last post: by
2 posts views Thread by Ghost | last post: by
2 posts views Thread by quest | last post: by
5 posts views Thread by Gilgamesh | last post: by
3 posts views Thread by GaryDean | last post: by
13 posts views Thread by clintonG | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.