473,398 Members | 2,404 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,398 software developers and data experts.

What could cause XML files to not be completely written?

We've had a month long headache with one of our functions in the CMS we've
built.

Whenever a page is updated in our CMS, we do a recursive call to the DB to
get all the pages (and child pages, and child child pages, etc.) and then
create an XML file, and save that to the filesystem. The front end then uses
that XML file along with some XSL to create the site menus, site maps, etc.

We're having a problem where 99 out of 100 times, this works fine. But that
one time, we'll get an incomplete (and therefore invalid) XML file written
to the filesystem. No error. Nothing. Just a bad file.

What could be the possible causes of this? I've included the function that
writes the XML at the bottom of this message if that helps.

At this point, we're looking into two solutions which just seem a bit hacky:

1) write the file, open the file, validate it, if invalid, write again,
repeat a few times and then report an error if you have to.

2) forget the filesystem. Write the XML file as a VARCHAR back into a DB
table and just grab it from there.

Any other thoughts? Things to look out for? Solutions? Theories?

Thanks!

------------------------------------------------------------------

Imports System.IO
Public Class menuWriter
Shared fs As System.IO.FileStream
'shared objXMLWriter As system.xml.XmlTextWriter

Shared Sub createXMLfileWithXmlWriter(ByVal parentNode As Integer, ByVal
intLevel As Integer, ByVal rowCount As Integer, ByVal createParentNode As
Boolean, ByVal siteID As Integer)
Try
' Create the parent node
'dim objXMLWriter As system.xml.XmlTextWriter
' xml writing adapted from
' http://www.developerfusion.com/show/2646/
If
System.IO.Directory.Exists(System.Web.HttpContext. Current.Server.MapPath("/mjb05/xml/"
& siteID)) Then
'directory exists. Do nothing
Else
'directory doesn't exist. Creat directory
System.IO.Directory.CreateDirectory(System.Web.Htt pContext.Current.Server.MapPath("/mjb05/xml/"
& siteID))
End If

Dim objXMLWriter As System.Xml.XmlTextWriter
Dim path As String =
System.Web.HttpContext.Current.Server.MapPath("/mjb05/xml/" & siteID &
"/siteMenu.xml").ToString
fs = New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)
SyncLock fs
objXMLWriter = New System.xml.XmlTextWriter(fs,
System.Text.Encoding.Default)
objXMLWriter.Formatting = objXMLWriter.Formatting.Indented
objXMLWriter.Indentation = 3
objXMLWriter.WriteStartDocument()
objXMLWriter.WriteComment("Created on " & Now())
objXMLWriter.WriteStartElement("menuItems")
WriteXmlData(objXMLWriter, parentNode, siteID)
objXMLWriter.WriteEndElement() 'close menuItems node
objXMLWriter.WriteEndDocument() 'close docment
objXMLWriter.Flush()
objXMLWriter.Close()
End SyncLock
Catch ex As Exception
System.Web.HttpContext.Current.Response.Write("Err or writing XML file<br
/>")
System.Web.HttpContext.Current.Response.Write(ex.M essage.ToString)
End Try
End Sub

Shared Sub WriteXmlData(ByVal objXMLWriter As System.Xml.XmlTextWriter,
ByVal parentNode As Integer, ByVal siteID As Integer, Optional ByVal
intLevel As Int32 = 0)
'retrieve all children of parentNode
' grab the data from the db
Dim DS As New DataSet
Dim strConnect As String
strConnect =
System.Configuration.ConfigurationSettings.AppSett ings("DBConn")
Dim strChk As String
strChk = "SELECT pageID, siteID, parentID, linkText, browserTitle,
contentTitle, hidden, sort, customContent, customContentVariables,
menuCategory, isCategory, homePage " & _
"FROM WeSiteMenus " & _
"WHERE ParentID = " & parentNode & " AND siteID = " & siteID & " " & _
"ORDER BY homePage DESC, sort ASC"
Dim objConnect As New System.Data.OleDb.OleDbConnection(strConnect)
objConnect.Open()
Dim objCommand As New System.Data.OleDb.OleDbCommand(strChk, objConnect)
Dim objOleDbAdapter As New System.Data.OleDb.OleDbDataAdapter(strChk,
strConnect)
objOleDbAdapter.Fill(DS, "webPages")

' Walk through results whether it's a list or a single contact.
' based off of this tutorial:
' http://www.wwwcoder.com/main/parenti...8/default.aspx
Dim rowCount As Int32 = 0
While rowCount < DS.Tables(0).Rows.Count 'ie, if there IS data, then...
objXMLWriter.WriteStartElement("menuItem")

objXMLWriter.WriteElementString("pageID",
Trim(DS.Tables(0).Rows(rowCount)("pageID").ToStrin g))
objXMLWriter.WriteElementString("parentID",
Trim(DS.Tables(0).Rows(rowCount)("parentID").ToStr ing))
'linkURL...need to actuall add this to the DB!
objXMLWriter.WriteElementString("linkURL", "")
objXMLWriter.WriteElementString("linkText",
Trim(DS.Tables(0).Rows(rowCount)("linkText").ToStr ing))
objXMLWriter.WriteElementString("browserTitle",
Trim(DS.Tables(0).Rows(rowCount)("browserTitle").T oString))
objXMLWriter.WriteElementString("contentTitle",
Trim(DS.Tables(0).Rows(rowCount)("contentTitle").T oString))
objXMLWriter.WriteElementString("hidden",
Trim(DS.Tables(0).Rows(rowCount)("hidden").ToStrin g))
objXMLWriter.WriteElementString("customContent",
Trim(DS.Tables(0).Rows(rowCount)("customContent"). ToString))
objXMLWriter.WriteElementString("customContentVari ables",
Trim(DS.Tables(0).Rows(rowCount)("customContentVar iables").ToString))
objXMLWriter.WriteElementString("menuCategory",
Trim(DS.Tables(0).Rows(rowCount)("menuCategory").T oString))
objXMLWriter.WriteElementString("isCategory",
Trim(DS.Tables(0).Rows(rowCount)("isCategory").ToS tring))
objXMLWriter.WriteElementString("level", intLevel.ToString)
'now call the subroutine we're in to see if this value has
'any children and increase the indent, and so on...
WriteXmlData(objXMLWriter,
Convert.ToInt32(DS.Tables(0).Rows(rowCount).Item(0 )), siteID, intLevel + 1)
rowCount = rowCount + 1
objXMLWriter.WriteEndElement() 'close menuItem node
End While
' clean up
objConnect.Close()
objOleDbAdapter.Dispose()
objCommand.Dispose()
End Sub
End Class
May 11 '06 #1
3 1471
darrel wrote:
We've had a month long headache with one of our functions in the CMS we've
built.

Whenever a page is updated in our CMS, we do a recursive call to the DB to
get all the pages (and child pages, and child child pages, etc.) and then
create an XML file, and save that to the filesystem. The front end then uses
that XML file along with some XSL to create the site menus, site maps, etc.

We're having a problem where 99 out of 100 times, this works fine. But that
one time, we'll get an incomplete (and therefore invalid) XML file written
to the filesystem. No error. Nothing. Just a bad file.
You mean the file just ends in mid-element or something?
The only obvious things that come to mind are a buggy serializer
or a timing problem between the DB and the OS or disk subsystem.
What could be the possible causes of this? I've included the function that
writes the XML at the bottom of this message if that helps.

At this point, we're looking into two solutions which just seem a bit hacky:

1) write the file, open the file, validate it, if invalid, write again,
repeat a few times and then report an error if you have to.

2) forget the filesystem. Write the XML file as a VARCHAR back into a DB
table and just grab it from there.


Easier would be to run an external standalone validator (ie unconnected
to and independent of any other part of your system) which will pass
control onwards if the file is OK, but otherwise terminate the process
and restart it at the file export step.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
May 11 '06 #2
> You mean the file just ends in mid-element or something?

Yep. It'll just cut of mid-element. Randomly anywhere in the document.
The only obvious things that come to mind are a buggy serializer
I'm not sure if I'd know what to look for regarding that. What would that
actually be?
or a timing problem between the DB and the OS or disk subsystem.
Well, I'm grabbing all the data from the DB at once, and then writing it to
the XML file in one swoop, so that probably isn't it. No doubt it could be
the OS or disk subsystem, though. NO idea how to even begin to figure out
what specifically to look at in that context, though.
Easier would be to run an external standalone validator (ie unconnected
to and independent of any other part of your system) which will pass
control onwards if the file is OK, but otherwise terminate the process
and restart it at the file export step.


Whoa. So, I'd be passing something to another app and back again? I'm not
sure if that sounds easier to me ;o)

What kind of external validator are we talking about? Just another web app
that I'd whip up? What would be the advantage of externalizing the validator
(vs just validating what was written in the app itself?)

-Darrel
May 11 '06 #3
darrel wrote:
What kind of external validator are we talking about? Just another web app
that I'd whip up? What would be the advantage of externalizing the validator
(vs just validating what was written in the app itself?)


Any of the standalone parsers will do: it doesn't actually have to
validate if all you want is to test the file's completeness. If we
assume that the file is either complete (and correct) or incomplete
(and that no other mid-way corruption takes place) then a simple
well-formedness check will show if the file is complete or not.

My reason for suggesting an external process was simply to guarantee
that the parse was not being affected by anything else that might have
gone on inside your app.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
May 13 '06 #4

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

Similar topics

92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
4
by: Jeff Grundy | last post by:
I am using the FileSystemWatcher to watch a folder for new file. The new files will be very large. The Created event is fired when the new file first appears in a folder. How do I know when the file...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
23
by: JDeats | last post by:
Just spent some time browsing around here: http://msdn.microsoft.com/Longhorn/ I can see the benefits from WinFS (as long as we tag all in-coming data this should be nice, tagging everything...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
2
by: James | last post by:
CASE 1: The following sentences were copied from the book "Administration Guide Performance". "If more pages have been written to disk, recovery of the database is faster after a system crash...
15
by: jim | last post by:
Maybe I'm missing something, but it doesn't look like Microsoft writes a lot of apps in .Net (although they certainly push it for others). What does MS write using pure .Net? If applications...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.