473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 3511
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lee Atkinson | last post by:
Hi - I am trying to read an XML file using XmlTextReader and write it out using XmlTextWriter. The XML is XHTML. At the moment, I am trying to create a straightforward copy of a file. The XHTML...
3
by: K Rege | last post by:
Hi there, I tried to implement a little XML-EchoServer using Sockets and XmlTextWriter/Reader. However the server hangs while reading the input from the client (wr.Flush() seams not to work). I...
2
by: Ghost | last post by:
Can anybody how do I use XmlTextWriter example? I want to write such XML file: <?xml version="1.0" standalone="yes"?> <Clients> <Client> <Name>David</Name> <Age>27</Age> </Client>
2
by: quest | last post by:
XmlTextWriter writer = new XmlTextWriter("c:\\myxml.xml", System.Text.Encoding.UTF8); writer.WriteStartDocument(true); writer.WriteStartElement("Heading"); writer.WriteAttributeString("Ver",...
8
by: Marc Gravell | last post by:
I want to write a method that will accept a stream as a parameter, and which will write xml to the stream (based in reality on database results) using the XmlTextWriter class. However, this insists...
5
by: Gilgamesh | last post by:
Hello, How do I use this class to create an XML document without saving it into a file? I need to store the XML documen into a string so it could be passed as a parameter to another class....
3
by: GaryDean | last post by:
I'm using an XmlTextWriter and it's various methods such as WriteElementString, WriteStartElement, WriteEndElement, etc to create an xml document. When I instantiate the XmlTextWriter to a file......
13
by: clintonG | last post by:
// I want this format... <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"> The WriteStartElement is used for the rss element and...
4
prabirchoudhury
by: prabirchoudhury | last post by:
Hey all I am tryng to do convert files details as base64 format and then wrireRaw into the xml file in php 5.1.2 and then covert it back to the original file format, but writeRaw is not supported...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.