473,624 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlDocument.Wri teTo method truncating at 2048 characters

I am attempting to write an XmlDocument to file, but for some reason it will
only write 2048 characters of the document even though when I stop it in the
debugger ALL of the document is there.

Code snippet is as follows:

XmlDocument xml = new XmlDocument();
xml.LoadXml(Enc oding.UTF8.GetS tring(btRespons e));
XmlTextWriter w = new XmlTextWriter(" ..\\..\\..\\xml \\Test.xml", null);
xml.WriteTo(w); // will not write anything after 2048 bytes

Any suggestions?
Jul 28 '06 #1
2 2849
William <nf*@nospam.com wrote:
I am attempting to write an XmlDocument to file, but for some reason it will
only write 2048 characters of the document even though when I stop it in the
debugger ALL of the document is there.

Code snippet is as follows:

XmlDocument xml = new XmlDocument();
xml.LoadXml(Enc oding.UTF8.GetS tring(btRespons e));
XmlTextWriter w = new XmlTextWriter(" ..\\..\\..\\xml \\Test.xml", null);
xml.WriteTo(w); // will not write anything after 2048 bytes

Any suggestions?
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

My guess is that you're not disposing it, so the underlying stream
isn't getting closed.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 28 '06 #2
Not closing was the problem... thx.

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
William <nf*@nospam.com wrote:
>I am attempting to write an XmlDocument to file, but for some reason it
will
only write 2048 characters of the document even though when I stop it in
the
debugger ALL of the document is there.

Code snippet is as follows:

XmlDocument xml = new XmlDocument();
xml.LoadXml(En coding.UTF8.Get String(btRespon se));
XmlTextWrite r w = new XmlTextWriter(" ..\\..\\..\\xml \\Test.xml", null);
xml.WriteTo(w) ; // will not write anything after 2048 bytes

Any suggestions?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

My guess is that you're not disposing it, so the underlying stream
isn't getting closed.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jul 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13769
by: Zoury | last post by:
Hi folks ! :O) I'm trying to show a PDF in ASP.NET but I can't get to work properly. here's a portion of my code : '** Dim ms As MemoryStream = DirectCast(m_report.FormatEngine.ExportToStream(reqContext), MemoryStream) If (fileName Is Nothing) Then
5
3609
by: Jack Fox | last post by:
I'm still new to Xml, but finding it very useful. Conceptually what I want to do is compress an XmlDocument, save it to SQL Server as image data, read it back and restore it to an XmlDocument. I'm a bit bewildered by the choices available (XmlSerialization, XmlWriter, Xml on SQL Server) and do not have any experience with them, so I was wondering what is the best way to do this?
13
22950
by: Matthew Wieder | last post by:
In my C# application, I have class which has method that opens an XML document, modifies it and saves it out. I run that method for several different XML documents. What I've found is that the Load emthod on the MXLDocument isntance loads the document into memory (as it should) but I have no way of releaseing that memory throughout the application, and I run out of memory. The documents I'm loading are abou 10 MB in size, and I run out...
2
4653
by: David Withnall | last post by:
Okay I am using an XMLDocument object to process several thousands of lodgements (from a database) I am trying to output it from an XML Document to a file using the XmlDocument.WriteTo() method with an XmlWriter. It writes 131kB and then cuts out halfway through an element Is this a limitation of XmlDocument.WriteTo() ? What would be a better way to output it Thanks
3
9045
by: Dan | last post by:
Is there a better way to include the XML declaration than the following? XmlDeclaration dec =m_XMLDocument.CreateXmlDeclaration("1.0",string.Empty, "yes"); m_XMLDocument.InsertBefore((XmlNode)dec, (XmlNode)m_XMLDocument.DocumentElement); XmlTextWriter writer = new XmlTextWriter(m_FileName,Encoding.Default); writer.WriteRaw(m_XMLDocument.OuterXml); writer.Flush();
2
2965
by: Charles.Deisler | last post by:
I'm reading a xmldocument in from the file system and using xmldocument.writeto(xmltextwriter) to stream the xml data to the response.outputstream. From what i've read, reading an xmldocument is thread safe but does the writeto() method require a lock? Thanks in advance!
1
1636
by: Robin Hay | last post by:
I have created a class which inherits from XmlDocument. It works as I expected. If I use Visual Studio, and type a <carriage return> after "inherits XmlDocument", VS adds three method overrides. These seem to make sense, but then the class doesn't behave as I intended, or as it did if I typed in the data myself. See example below. Imports System.xml Module Module1
5
2526
by: Andy Fish | last post by:
Hi, I am using XmlDocument.WriteTo() and I find that the xml declaration is not included. at the moment I am doing this: XmlTextWriter xw = new XmlTextWriter(...); xw.WriteStartDocument(); doc.WriteTo(xw);
5
6186
by: Gustaf | last post by:
I've been trying to update my code to the new XslCompiledTransform class without success. The following method takes an XML and XSL file, and returns an XmlDocument object. Can anyone figure out how to write the parameters to the XslCompiledTransform.Transform() method in this case? static XmlDocument Transform(string xml, string xsl) { try { XmlDocument xmlDocIn = new XmlDocument();
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8348
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2613
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.