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/x
ml/"
& 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("/mjb
05/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> 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
darrel wrote:
> 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.
> 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
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment