473,399 Members | 3,656 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,399 software developers and data experts.

Why is my XML file being written corrupt?

In our CMS, every time a page is updated, we spit out a new XML file.

This file is written via a function that queries the Database using a
recursive function, grabs the data, and writes out a file using
xmltextwriter:

Dim fs As New
System.IO.FileStream(System.Web.HttpContext.Curren t.Server.MapPath("/mjb05/xml/"
& siteID & "/siteMenu.xml").ToString, IO.FileMode.Open, IO.FileAccess.Write,
IO.FileShare.Read)
objXMLWriter = New System.xml.XmlTextWriter(fs, Nothing)
'objXMLWriter = New
System.xml.XmlTextWriter(System.Web.HttpContext.Cu rrent.Server.MapPath("/mjb05/xml/"
& siteID & "/siteMenu.xml").ToString, Nothing)
objXMLWriter.Flush()
objXMLWriter.Formatting = objXMLWriter.Formatting.Indented
objXMLWriter.Indentation = 3
objXMLWriter.WriteStartDocument()
objXMLWriter.WriteComment("Created on " & Now())
objXMLWriter.WriteStartElement("menuItems")
createParentNode = False

....etc.

This works 99% of the time. However, if I change a particular value in one
of my table cells the writer still executes, but then writes out an invalid
ending to the file.

What is REALLY odd is that I can re-write the file a second time and it
fixes itself.

What is even odder (yes, it gets odder) is the way the file is corrupted.
It's appending a weird bit of broken nodes to the end of the file.

For instance, if my file SHOULD end like this:

</endNode>
</endAllItems>

the corrupted file might look like this:

</endNode>
</endAllItems>
</endNode>
</endAllItems>

or this:

</endNode>
</endAllItems>endNode>
</endAllItems>

or even just this:

</endNode>
</endAllItems>s>

Anyone have any ideas what could cause this type of weird corruption when
writing out an XML file?

-Darrel
Apr 5 '06 #1
3 1830
> This works 99% of the time. However, if I change a particular value in one
of my table cells the writer still executes, but then writes out an
invalid ending to the file.


Some more info:

I've looked at the data in the db when writing:

data record 1 = writes XML file
data record 2 = writex XML file
return to data record 1 = writes CORRUPTED file
write again with data record 1 = writes XML file

In all instance, the same variables are passed to the function that writes
out the xml file.

In addition, the corruption is random but consistent (make sense? ;o)

It's always one or two (possibly partial) repeats of the last node and the
parent node closing tags at the end of the file.

-Darrel
Apr 5 '06 #2
darrel wrote:
This works 99% of the time. However, if I change a particular value in one
of my table cells the writer still executes, but then writes out an
invalid ending to the file.


Some more info:

I've looked at the data in the db when writing:

data record 1 = writes XML file
data record 2 = writex XML file
return to data record 1 = writes CORRUPTED file
write again with data record 1 = writes XML file

In all instance, the same variables are passed to the function that writes
out the xml file.

In addition, the corruption is random but consistent (make sense? ;o)

It's always one or two (possibly partial) repeats of the last node and the
parent node closing tags at the end of the file.

-Darrel

To me it looks like a logic fault in your recursive functions. It might
be there is a fault in how elements are being closed and taken care of.
Step through the code for a small XML file and see where the problem is.
Apr 6 '06 #3
> To me it looks like a logic fault in your recursive functions. It might
be there is a fault in how elements are being closed and taken care of.
Step through the code for a small XML file and see where the problem is.


I'll give it a shot. However, my function is using xmlwriter to write out
individual nodes so even if it is a logic error, it's hard to figure out why
it would be writing half-tags.

I'll report back!

-Darrel
Apr 6 '06 #4

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

Similar topics

3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
5
by: Vinay | last post by:
Hi I have a corrupt word file. I am able to open it with the code given below tr Dim pInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo( pInfo.UseShellExecute...
18
by: rdemyan via AccessMonster.com | last post by:
Here's my plan for creating nightly backups of the production back-end file (the IT staff in their infinite wisdom have prevented use of Windows Scheduler and users do not have administrative...
7
by: eventuranza | last post by:
For my application, there users can upload and download files to the a webserver. Straightforward enough. However, when they upload a PDF file then try to download it, the file seems to be...
5
by: Digital Puer | last post by:
I fixed a bug today that went against my intuition. I am on Linux. I had a class that fopen'ed some files. When I called delete on these objects, I expected that the files would be closed...
8
by: =?Utf-8?B?Q2hyaXMgRmluaw==?= | last post by:
I am trying to make a minor modification to the code below and need some assistance. Currently this code is using the java.util, java.util.zip, and java.io assemblies from the vjslib.dll assembly....
4
by: GS | last post by:
How do I fix this corrupt resource file header problem? Corrupt .resources file. Got an unexpected EndOfStreamException while trying to read the ResourceReader header. When I open up properties,...
1
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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...
0
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,...

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.