Solved

XML unloading a file from memory (using DOM, Classic ASP)

Posted on 2006-10-22
3
781 Views
Last Modified: 2012-08-13
I need some assistance with deleting an existing XML file.  My classic ASP program produces an XML file but first it needs to see if a prior one exists.  If one does exist, then I need to delete the old XML file before starting a new one.  The problem with my logic is that I am loading the existing XML into memory and then deleting the physical file.  How do I unload it from memory?  This is causing my program to crash.  

Here is my code right now:

 strFilename = "Apogee1.xml"  
 strXMLFile=server.mapPath(strFilename)  
 Set oXML = Server.CreateObject("Microsoft.XMLDOM")
 Set oXML.DocumentElement = oXML.createElement("P21_VPT_DATA")
 Set oFSO = Server.CreateObject("Scripting.FilesystemObject")
 
' check file exists  
 bitFileExists = oXML.load(strXMLFile)  
 
 if bitFileExists then
    oFSO.DeleteFile(strXMLFile)    ?? This will delete the physical file but does not clear out memory from oXML.load.
  end if  
 
 oXML.appendChild(oXML.createProcessingInstruction("xml","version=""1.0"""))  
 Set oChild = oXML.appendChild(oXML.createElement("BillingData"))        ???? my program will crash here if an existing file was loaded into memory.  
0
Comment
Question by:Hojoformo
3 Comments
 
LVL 9

Expert Comment

by:Hypnochu
Comment Utility
In your previous question, I was using the filesystemobject to check whether the file exists then deleting it before loading it.
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_22033261.html
Don't know if you missed it there (I'd feel kind of guilty taking the points twice for the same thing)?


strFilename = "Apogee1.xml"  
 strXMLFile=server.mapPath(strFilename)  
 Set oXML = Server.CreateObject("Microsoft.XMLDOM")
 Set oXML.DocumentElement = oXML.createElement("P21_VPT_DATA")
 Set oFSO = Server.CreateObject("Scripting.FilesystemObject")
 
' check file exists  
bitFileExists = oFSO.FileExists(strXMLFile)  
 
 if bitFileExists then
    oFSO.DeleteFile(strXMLFile)    
  end if
 
 bitFileExists = oXML.load(strXMLFile)
 
 oXML.appendChild(oXML.createProcessingInstruction("xml","version=""1.0"""))  
 Set oChild = oXML.appendChild(oXML.createElement("BillingData"))  
0
 

Author Comment

by:Hojoformo
Comment Utility
Hi Hypnochu,

    There must be something else wrong.  My program keeps crashing right after it deletes the file with the following message.  Line 312 is "Set oChild = oXML.appendChild(oXML.createElement("BillingData"))".  I thought it had something to do with oXML.load but that is not the problem.   Any suggestions?


Error Type:
msxml3.dll (0x80004005)
Only one top level element is allowed in an XML document.
/Apogee/residential/account_history2.asp, line 312

My code:

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
      ' find xml file path
 dim oXML       
 dim strFilename,strXMLFile
 dim bitFileExists
 dim intCurrentRecord
 dim tmpChildnodes
 dim oXMLRec
 dim oAtt
 dim oXMLData
 dim oChild
 dim oFSO
 strFilename = "Apogee9.xml"  
 strXMLFile=server.mapPath(strFilename)  
 Response.Write("strXMLFile = " & strXMLFile)
 
 Set oFSO = Server.CreateObject("Scripting.FilesystemObject")

 ' check file exists
 bitFileExists = oFSO.FileExists(strXMLFile)  
 
 'bitFileExists = oXML.load(strXMLFile)  
 
 if bitFileExists then
    oFSO.DeleteFile(strXMLFile)
    'tmpChildnodes = oXML.documentElement.childnodes.length - 1  
    'intCurrentRecord = tmpChildnodes + 1  
 end if  
 Set oXML = Server.CreateObject("Microsoft.XMLDOM")
 Set oXML.DocumentElement = oXML.createElement("P21_VPT_DATA")
 
 oXML.appendChild(oXML.createProcessingInstruction("xml","version=""1.0"""))  
 Set oChild = oXML.appendChild(oXML.createElement("BillingData"))
 oChild.setAttribute "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"
 oChild.setAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
 oChild.setAttribute "xmlns", "http://apogee.net/WebService"

 intCurrentRecord = 0  
 
 ' create record  
 'Set oXMLRec = oXML.appendChild(oXML.createElement("UtilityId"))
 Set oXMLRec = oXML.createElement("UtilityId")  
 'oXML.documentElement.appendChild(oXMLRec.cloneNode(True))
 oXMLRec.setAttribute "ID", myaccount
 'oXML.documentElement.appendChild(oXMLRec.cloneNode(True))  
 
 ' Create an id attribute  
 'Set oAtt = oXML.createAttribute("id")  
 'oAtt.Text = intCurrentRecord  
 'oXMLRec.SetAttributeNode oAtt  
 
 ' Set remaining fields  
 dim oXMLData1
 Set oXMLData1 = oXML.CreateElement("BillingCycleData")
 oXML.documentElement.appendChild(oXMLData1.cloneNode(true))  



0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
Comment Utility
Try changing

Set oChild = oXML.appendChild(oXML.createElement("BillingData"))

to

Set oChild = oXML.documentElement.appendChild(oXML.createElement("BillingData"))
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now