Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load file to memory 2

Status
Not open for further replies.

nickdel

Programmer
May 11, 2006
367
GB
I've put together a quick XML reader at work and I'm wondering if it's possible to load a XML file to the server memory, read it, display to user and then dump it? i.e. I dont want to physically store the file on the server.

Thanks

Nick

 
Where are you planning on reading the file from? The two places I could think of off the top of my head that would give you XML to read without any files would be POSTed XML and the user using a file input to upload an XML file.
In the first case you can retrieve the XML as text data from Request.Form (without specifying a key), in the second case it gets much more complicated.

Best MS KB Ever:
 
Tarwin, I like the idea of posting the XML, hadn't thought about that. The users recieve the XML as a file, unfortunately due to restrictions on the web server I cannot put just a standard upload script as permission is denied.
 
Tarwin, sorry but if I'm using Microsoft.XMLDOM doesn't it have to be a physical file that I load? Here's my code which loads the XML from a file that is saved on the web server (I put this one there but I want to remove the dependancy on me doing this)

Code:
Sub ReadXML(FileName)

if not FileName="" then

 Set objXML = Server.CreateObject("Microsoft.XMLDOM")
 Set objLst = Server.CreateObject("Microsoft.XMLDOM")
 objXML.async = False
 objXML.Load (Server.MapPath("XMLUpload/" & FileName))


 Set objLst = objXML.getElementsByTagName("*")
 
 
 %>
 <table style="border: 1px solid black;">
 <% 


 For i = 0 to (objLst.length - 1)


		treeWalk(objLst.item(i))
    
 Next
 
 end if
 
 
set objXML = nothing
set objLst = nothing 
 
end sub
 
Sub treeWalk(node)

	 For Each child In node.childNodes
	 
	 if not (isnull(trim(child.text)) or trim(child.text)="") then
	 response.write "<tr>"

		 If (child.hasChildNodes) Then
		 
		 	 if not LastNode = node.Tagname then
				 for j = 0 to node.attributes.length-1
					AttString = AttString & node.nodename & "=" & node.attributes(j).nodevalue & " "
				 next
		 	 
				 response.write "<td colspan=2 style=""border: 1px solid black; background:#666699;"">" &_
								node.Tagname & " " & AttString & "</td>"
			 end if
			
			Lastnode = node.Tagname
		 	treeWalk(child)
		 
		 else
		 

				response.write "<td style=""border: 1px solid black; background:#ccccff;"">" &_
							node.Tagname & "</td><td style=""border: 1px solid black; background:#F8FBBD;"">" &_
							child.text & "</td>"
		 end if
		 
		response.write "</tr>"	 
		end if
	 Next
	 
End Sub

So, as you can see, its a simply XML to HTML reader.

Is it therefore possible, using Microsoft.XMLDOM, instead of loading a physical file, a user can just input the XML to a textarea, post this and then have the parser read it?

Hope I'm making sense!

Nick
 
>Is it therefore possible, using Microsoft.XMLDOM, instead of loading a physical file, a user can just input the XML to a textarea, post this and then have the parser read it?
This is how you can do it.

[1] Modify the sub readxml, let me call it sub do_readxml to preserve continuity. (I put the table tag in response.write as well to avoid an unnecessary jump. Also I would write a table close tag as well---you should do the same.)
[tt]
[red]'[/red]Sub ReadXML(FileName)
Sub [blue]do_[/blue]ReadXML([blue]sxml[/blue])

[red]'[/red]if not FileName="" then
[blue]if sxml<>"" then[/blue]

Set objXML = Server.CreateObject("Microsoft.XMLDOM")
Set objLst = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.Load[blue]XML[/blue] sxml

[blue]if objXML.parseError.ErrorCode = 0 then[/blue]

Set objLst = objXML.getElementsByTagName("*")

[blue] response.write "<table style=""border: 1px solid black;"">"[/blue]

For i = 0 to (objLst.length - 1)

treeWalk(objLst.item(i))

Next

[blue]end if[/blue]
end if

[blue]response.write "</table>"[/blue]

set objXML = nothing
set objLst = nothing

end sub
[/tt]
ps: add provisions for the two "else" of the two "if".

[2] Before the sub, it is called like this.
[tt]
<%
dim s
s=request.form("txtarea") [blue]'txtarea is the name of the textarea of the original page posting[/blue]
do_ReadXML s
'...etc etc those two sub
%>
[/tt]
The sceen is then set.
 
tsuji, exactly what I needed, thank you very much!

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top