Why is my XML file being written corrupt?

D

darrel

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.Current.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.Current.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
 
D

darrel

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
 
R

Ray Booysen

darrel said:
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.
 
D

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top