Solved

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

Posted on 2006-10-22
3
793 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
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Select distinct 25 115
Auto Submit on dropdown box 14 72
How to alternate between 2 messages until page closes in Classic ASP 8 38
Hide cell in a table 2 27
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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