Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-10-22
3
Medium Priority
?
801 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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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 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 informatio…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 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