PDA

View Full Version : Help! Xml Asp Problem


ordonyez
11-26-2005, 09:06 PM
Hi,

Im creating a forum using xml and asp. in my form to add a new post in my input tags i have the value as <% =Request( "userName" ) %> . This is to retreive the value and put it in a variable username. However, when I view the page my asp code is showing up in the input boxes. PLEASE HELP ME FIGURE THIS OUT!! Below is the code for this page. and attached is a screenshot of what I see when I open the asp page.



<% @LANGUAGE = "VBScript" %>

<%

Option Explicit

Dim xmlFile, xmlRoot, xmlNode
Dim strTitle, strError, strPath

If Request( "submit" ) <> Empty Then

If Request( "file" ) <> Empty And _
Request( "userName" ) <> Empty And _
Request( "messageTitle" ) <> Empty And _
Request( "messageText" ) <> Empty Then

strPath = Server.MapPath( Request( "file") )

Set xmlFile = Server.CreateObject( "Microsoft.XMLDOM" )
xmlFile.Async = False

If Not xmlFile.Load( strPath ) Then
Call Server.Transfer( "invalid.html" )
End If

'get the root node
Set xmlRoot = xmlFile.DocumentElement

'create first message
Set xmlNode = xmlFile.CreateElement( "message" )
Call xmlNode.SetAttribute( "timestamp", Now & " EST" )
Call xmlRoot.AppendChild( xmlNode )

Set xmlRoot = xmlNode

'Create User Node
Call CreateElementNode( "user", "userName", xmlNode )


'Create Title Node
Call CreateElementNode( "title", "messageTitle", xmlNode )


'Create Text Node
Call CreateElementNode( "text", "messageText", xmlNode )

'Save The File
Call xmlFile.Save( strPath )

'Finished Processing
Call Server.Transfer( Request( "file" ) )

Else
strError = "ERROR: Invalid input."
End If

End If



' procedure that creates an element node

Sub CreateElementNode( elementName, formElement, node )
Set xmlNode = xmlFile.CreateElement( elementName )
xmlNode.Text = Request( formElement )
Call xmlRoot.AppendChild( node )
End Sub
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml">

<head>
<title>Post A Message</title>
<link rel= "stylesheet" type="text/css" href="style.css" />
</head>

<body>
<p><% =strError %></p>

<form method="post" action="addPost.asp">

<p>
User:<br />
<input type = "text" size = "40" name= "userName" value="<% =Request( "userName" ) %>" />
</p>


<p>
Message Title:<br />
<input type="text" size="40" name="messageTitle" value= "<% =Request( "messageTitle" ) %>" />
</p>

<p>
Message Text:<br />
<textarea name="messageText" cols="40" rows="4"><% =Request( "messageText" ) %>
</textarea>
</p>

<p>
<input type="hidden" name="file" value= " <% =Request( "file" ) %> " />
<input type="submit" name="submit" value="submit" />
<input type="reset" value="Clear" />
</p>
</form>

<p>
<a href= "<% =Request( "file" ) %>" >Return to Forum</a>
</p>
</body>
</html>