Solved

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

Posted on 2006-10-22
3
796 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:Hypnochu
ID: 17784496
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
ID: 17784704
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
ID: 17786797
Try changing

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

to

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 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