-
how to check for blank values in xml
We are using an html page with input boxes and then passing to xml tags which
goes to an asp page to update an Access database. The problem we are having
is that if a user leaves a value blank, we get a strange error that says
"page cannot be displayed." Our database fields allow for zero length and
are not required. How can we modify our asp page to check to make sure that
the fields have been filled out. Our asp page is below. Thank you in advance
for any suggestions.
<%@Language= VBScript %>
<%
Response.ContentType = "text/html"
Set docReceived = CreateObject ("Microsoft.XMLDOM")
docReceived.async = False
docReceived.load Request
'Add an XML Schema to root node of document
Set rootnode = docReceived.documentElement
rootnode.setAttribute "xmlns", "x-schema:" & Server.MapPath("studentlistschema.xml")
'Create another XMLDOM object to validate the XML data
Set docTested = CreateObject("Microsoft.XMLDOM")
docTested.validateOnParse = True
docTested.async = False
docTested.loadXML(docReceived.xml)
'Is the document valid?
If docTested.parseError.errorCode = 0 Then
'Send "OK" message back to the client
Response.Write "The XML is valid!"
Else
'Send details of error back to the client
Response.Write "Invalid XML!" & vbCrLf
Response.Write "Line Number: " & CStr(docTested.parseError.line)
& vbCrLf
Response.Write "Character: " & CStr(docTested.parseError.linepos)
& vbCrLf
Response.Write "Source Text: " & docTested.parseError.srcText
& vbCrLf
Response.Write "Error code: " & CStr(docTested.parseError.errorCode)
& vbCrLf
Response.Write "Description: " & docTested.parseError.reason
& vbCrLf
Response.End
End If
Set Conn = CreateObject ("ADODB.Connection")
Conn.ConnectionString = "ProjectXML"
Conn.Open
Set ssnNode = docReceived.selectSingleNode("//ssn").childnodes
ssnid = ssnNode(0).nodevalue
Set fnameNode = docReceived.selectSingleNode("//fname").childnodes
fnameid = fnameNode(0).nodevalue
Set lnameNode = docReceived.selectSingleNode("//lname").childnodes
lnameid = lnameNode(0).nodevalue
Set streetNode = docReceived.selectSingleNode("//street").childnodes
streetid = streetNode(0).nodevalue
Set cityNode = docReceived.selectSingleNode("//city").childnodes
cityid = cityNode(0).nodevalue
Set stateNode = docReceived.selectSingleNode("//state").childnodes
stateid = stateNode(0).nodevalue
Set zipNode = docReceived.selectSingleNode("//zip").childnodes
zipid = zipNode(0).nodevalue
Set areaNode = docReceived.selectSingleNode("//area").childnodes
areaid = areaNode(0).nodevalue
Set phoneNode = docReceived.selectSingleNode("//phone").childnodes
phoneid = phoneNode(0).nodevalue
Set emailNode = docReceived.selectSingleNode("//email").childnodes
emailid = emailNode(0).nodevalue
SQL = "INSERT INTO student (ssn, fname, lname, street, city, state, zip,
area, phone, email) VALUES ('" & ssnid & "','" & fnameid & "','" & lnameid
& "','" & streetid & "','" & cityid & "','" & stateid & "','" & zipid & "','"
& areaid & "','" & phoneid & "','" & emailid & "')"
Conn.execute(SQL)
Response.Write " Thank you for registering. Your account has been added to
our database."
Conn.Close
%>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks