Solved

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

Posted on 2006-10-22
3
795 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weighted Randomizing 6 38
Syntax for query to update table 2 56
Reg Exp to extract Url from string asp 12 58
JSON Error in ASP Page 3 39
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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