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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLDOM and ASP

Status
Not open for further replies.

tmcneil

Technical User
Nov 17, 2000
294
US
Hi All,

I'm trying to use an asp page to store variables passed to it from another asp page via javascript. The test page looks like this:
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<!--#include file="include/database.asp"-->

<%    
    TakeID     = GetVal("TakeID", 0)
    TakeKindID = GetVal("TakeKindID", 0)
    LineID     = GetVal("LineID", 0)
%>
<form name="test"  action="test.asp" method="post" target="_self">
<input type="hidden" id="TakeID"	 name="TakeID"	   value="<%=TakeID%>">
<input type="hidden" id="TakeKindID" name="TakeKindID" value="<%=TakeKindID%>">
</form>

I am trying to use the hidden variables passed to this page to run some SQL queries to retrieve some records that will be used to output to an XML document. I guess, I need to create a test xml document using the hidden variables to make sure it works. Then, write the SQL queries to pull the records out prior to creating the xml document. So, what's the easiest way to tackle this problem?

By the way: I have some of the queries written in vbscript already. Will these go at the top of this test page?

Thanks, Todd
 
Well, maybe this was the wrong forum to post? I've written some more code and created this "test.asp" page to pass two values to. You will see then declared near the top. With those two values, I used them in queries to pull out recordsets. I create an XML object and loop through the records to print out two fields that I want to process later. The goal is to create an xml document with elements that I can parse out and use to store in a drop-down box for later use. Well, I guess this would be called AJAX. I'm pretty new to it, but am finding some resources on the net to learn how to use it through javascript. Anyways, here is my code and was wondering if there is anything that is syntactically incorrect or anything else wrong with it.
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<!--#include file="include/database.asp"-->

<%  
    ' TakeID and TakeKindID being passed from makeRequest(takeID, takekindID)
    ' Javascript function
    TakeID     = GetVal("TakeID", 0)
    TakeKindID = GetVal("TakeKindID", 0)

    Dim objXML

    ' Instantiate the XMLDOM Object that will hold the XML file
    set objXML = Server.CreateObject("Microsoft.XMLDOM")
    objXML.preserveWhiteSpace = True
    
    ' Check to see if document has data. If it does, don't build it 
    If (objXML.childNodes.length = 0) Then

	    set node = objXML.createProcessingInstruction("xml", "version='1.0'")
	    objXML.appendChild(node)
	    set root = objXML.createElement("CannedMessageSyncReq")
	    set attrib = objXML.createAttribute("xmlns")
	    'set attrib.text = "x-schema:CannedMessageSyncReqSchema.xml"
	    'set attributes = node.attributes
	    'attributes.setNamedItem(attrib)
	    objXML.appendChild(root)
	
	    ' Determine Line when given a TAKE_ID from Pivot drop-down
        Set cn = GetDBConnection()
        Set SQLStmt = Server.CreateObject("ADODB.Command")
        Set RS = Server.CreateObject("ADODB.Recordset")
        SQLStmt.CommandText = "SELECT DISTINCT LINE FROM LOCATION_TAKE_XREF_V " & _
                              "WHERE TAKE_ID = " & CStr(TakeID)
                          
        SQLStmt.CommandType = 1
        Set SQLStmt.ActiveConnection = cn
    
        RS.Open SQLStmt
        Do While Not RS.EOF
    
            ' Determine list of Take ID's for synched drop-downs
            Set cn = GetDBConnection()
            Set SQLStmt1 = Server.CreateObject("ADODB.Command")
            Set RS1 = Server.CreateObject("ADODB.Recordset")
            SQLStmt1.CommandText = "SELECT DISTINCT a.TAKE_ID, a.TAKE_DESCRIPTION "        & _
                                   "FROM LOCATION_TAKE_XREF_V a, LOCATION_TAKE_XREF_V b "  & _
                                   "WHERE a.LINE = " & CStr(RS("LINE")) & " AND "          & _
                                   "a.TAKE_KIND_ID = " & CStr(TakeKindID) & " AND "        & _
                                   "b.TAKE_ID = " & CStr(TakeID)                           & _
                                   "ORDER BY a.TAKE_ID ASC"
                           
            SQLStmt1.CommandType = 1
            Set SQLStmt1.ActiveConnection = cn
    
            'RS1.Open SQLStmt1
            'Do While Not RS1.EOF

                ' Set XML Elements for TakeID
                'set node = objXML.createElement("Take ID")
                'node.text = RS1("TAKE_ID")
                'root.appendChild(node)
            
                ' Set XML Elements for Take Description
                'set node = objXML.createElement("Take Description")
                'node.text = RS1("TAKE_DESCRIPTION")
                'root.appendChild(node)
            
                'RS1.MoveNext
            'Loop
            'RS1.Close
            'Set RS1 = Nothing
        
        RS.MoveNext
        Loop
        RS.Close
        Set RS = Nothing
    
        cn.Close
        Set cn = Nothing
    
        ' Save the XML doc
        'objXML.Save Server.MapPath("CanMsgSync.xml")
	
    	' Create and Send XML Response
	    Response.ContentType="text/xml"
        Response.Write(objXML.xml)
        
    End If
%>
I've commented out most of what didn't work, but that just gives me an empty xml document. So, the xml gets created, but there's something wrong with the code once I add the queries in.

Thanks in Advance,
Todd
 
Sheco,

GetVal() comes from the database.asp include file. it's a function that get the value of each variable. It's passed in, so the code sets it to what that value is.

Code:
Function GetVal(key, default)
    Dim val

    if Not IsEmpty(Request.Form(key)) then
	  val = Request.Form(key)
	  If TypeName(val) = "String" Then
	    If Len(val) = 0 Then
		  val = default
		End If
	  End If
	elseif Not IsEmpty(Request.QueryString(key)) then
	  val = Request.QueryString(key)
	  If TypeName(val) = "String" Then
	    If Len(val) = 0 Then
		  val = default
		End If
	  End If
	else
	  val = default
	end if

    ON ERROR RESUME NEXT
    Select Case TypeName(default)
      case "Integer" 
	    GetVal = CLng(val)
		if err.Number <> 0 then
		  GetVal = CLng(default)
		  err.Clear
		end if
	  case "Long"    
	    GetVal = CLng(val)
		if err.Number <> 0 then
		  GetVal = CLng(default)
		  err.Clear
		end if
	  case "String"  
	    GetVal = CStr(val)
		if err.Number <> 0 then
		  GetVal = CStr(default)
		  err.Clear
		end if
	  case "Double"  
	    GetVal = CDbl(val)
		if err.Number <> 0 then
		  GetVal = CDbl(default)
		  err.Clear
		end if
	  case "Null"
    End Select
End Function

I don't believe that it is the problem since it is used throughout alot of our web development. I'm more inclined to say that it's somewhere in my sql syntax or any code related to that section.
 
Let me see if I understand your architecture:

You have another page somewhere that has javascript that is using somehtin glike XMLHTTP to make a call back to this ASP page (basically falling under the umbrella of AJAX). This page needs to take the values it was passed, run a SQL statement, and respond back with XML to be parsed by the original page.

If all of that is correct then:
1) Type in an address for this page to aid in testing. Add some Response.Write's before and after each major step to see what's happning to your XML object

2) use Option Explicit and declare all of your variables, that way you would know if you were mispelling one

3) Your code works (for the document element and nodes at least, didn't bother checking the namespace declaration). I just commented out everything that has to do with the database and ran it and got back a document with an empty <CannedMessageSyncReq/>
The error you should be receiving inside your while loops is due to the fact that XML elements aren't allowed to have spaces in their names. I added an underscore, type in a value for the text line and uncommented one block inside my earlier commented version of your code and I got back an XML document with 1 element that had my text in it.


If your just getting <CannedMessageSyncReq/> then it is not an empty document. At this point I would assume that it has something to do with your SQL, especially since you haven't gotten the error message for attempting to add an XML tag with a space in it. Try Response.Write'ing your SQL statement and running it against the database yourself to see what issues it might be having.


My Opinion:
1) You don't need an XML object in this page. Since your returning XML than really all you need to do is Response.Write out your tags and data. Move your ContentType setting higher and just Response.Write the data in proper XML format. However I will note that it is handy to make sure your outputting everything in the right format, even if it does add overhead. In your case I would probably not change the code this late in the game.

2) You should be able to combine your two queries into a single query, which will reduce the logic needed for your output. Basically you should be able to Join the table from your first query with the tables from your second and just have a single query and recordset to loop through. This may help you determine the issue your SQL currently has as well.

 
Tarwn,

I've made some progress with the XML. I now have both SQL statements combined and the response coming back from the server. It looks to be correct, but I guess I now have to save that XML and learn how to parse it to populate the drop-down boxes on an asp page. The following represents how everything is working so far:

A drop down box from an asp page. When a value is selected, it fires off this javascript event, onChange="ValidateSel(this). Validate Sel() determines this value selected and a second value stored in a hidden variable on the form. Both values are passed to makeRequest() javascript function. makeRequest instantiates the xmlhttp request object. On open, a post is made with a url to the asp page to create the xml. The parameters containing two values are then sent. alertContents() is called on the onreadystatechange event of the http request to return the contents of the xml document. the asp page constructs the xml using the two values in a query and sends the request back to alertContent(). alertContents() views the xml request content in an alert box.

Instead of doing this alert box request, I need to figure out how to save the xml file and then parse it for use in the associated drop-downs. Here is the code of the asp page that creates the xml.
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<!--#include file="include/database.asp"-->

<%  
    '--------------------------------------------------------------------------
    ' TakeID and TakeKindID being passed from makeRequest(takeID, takekindID)
    ' javascript function
    '--------------------------------------------------------------------------
    TakeID     = GetVal("TakeID", 0)
    TakeKindID = GetVal("TakeKindID", 0)
    
    Dim strXMLFilePath, strFileName
    'Physical path of the root directory
    strXMLFilePath = Server.MapPath("/")
    'Response.Write strXMLFilePath
    strFileName = "CanMsgSync.xml"

    '--------------------------------------------------------------------------
    ' Create the XMLDOM Object that will hold the XML file
    '--------------------------------------------------------------------------
    Dim objXML
    set objXML = Server.CreateObject("Microsoft.XMLDOM")
    objXML.preserveWhiteSpace = True
    
    '--------------------------------------------------------------------------
    ' Check to see if objXML has data
    '--------------------------------------------------------------------------    
    If (objXML.childNodes.length = 0) Then

        '----------------------------------------------------------------------
        ' Create XML Document header
        '----------------------------------------------------------------------
	    set node = objXML.createProcessingInstruction("xml", "version='1.0'")
	    objXML.appendChild(node)	    
	    set root = objXML.createElement("CanMsgSyncReq")
	    set attrib = objXML.createAttribute("xmlns")
	    attrib.value = "x-schema: CanMsgSyncReqSchema.xml"
	    root.SetAttributeNode(attrib)
	    objXML.appendChild(root)
	    
	    '------------------------------------------------------------------
        ' Determine Take_ID and Take_Description of synched drop down
        ' controls
        '------------------------------------------------------------------  
        Set cn = GetDBConnection()
        Set SQLStmt1 = Server.CreateObject("ADODB.Command")
        Set RS1 = Server.CreateObject("ADODB.Recordset")
        SQLStmt1.CommandText = "SELECT DISTINCT a.TAKE_ID, a.TAKE_DESCRIPTION "       & _
                               "FROM LOCATION_TAKE_XREF_V a, LOCATION_TAKE_XREF_V b " & _
                               "WHERE a.LINE = (SELECT DISTINCT LINE FROM LOCATION_TAKE_XREF_V " & _
                               "                WHERE TAKE_ID = " & CStr(TakeID) & ")" & _
                               " AND   a.TAKE_KIND_ID = " & CStr(TakeKindID)          & _
                               " AND   b.TAKE_ID = " & CStr(TakeID)                   & _
                               " ORDER BY a.TAKE_ID ASC"
                               
        SQLStmt1.CommandType = 1
        Set SQLStmt1.ActiveConnection = cn
    
        RS1.Open SQLStmt1
        Do While Not RS1.EOF
 
            '--------------------------------------------------------------
            ' Create XML document elements
            '--------------------------------------------------------------
            set node = objXML.createElement("TAKE_ID")
            node.text = RS1("TAKE_ID")
            root.appendChild(node)
            
            set node = objXML.createElement("TAKE_DESCRIPTION")
            node.text = RS1("TAKE_DESCRIPTION")
            root.appendChild(node)
            
            RS1.MoveNext
        Loop
        RS1.Close
        
        Set RS1 = Nothing
    
    cn.Close
    Set cn = Nothing
    
    '--------------------------------------------------------------------------
    ' Save the XML doc
    '--------------------------------------------------------------------------
    'objXML.Save(strXMLFilePath & "\" & strFileName)
	
    '--------------------------------------------------------------------------
    ' Create and Send XML Response
    '--------------------------------------------------------------------------
	Response.ContentType="text/xml"
    Response.Write(objXML.xml)
        
    End If
%>

javascript functions:
Code:
///////////////////////////////////////////////////////////////////////////////
//
//  Routine: ValidateSel
//  
//  Purpose: Validate the selected item in the drop-down
//
//  Parameters: 
//      srcElement - 
//
//  Returns: 
//      Nothing.
// 
///////////////////////////////////////////////////////////////////////////////
function ValidateSel(item)
{
    var num = parseInt(item.id.substring(4));
	var ntakes = document.getElementById("ntakes").value;
	
	//Determine TakeID value from text1 drop-down box
	var takeID = document.getElementById("text1").value;
	
	var name, takekind, takekindID;
	if (item.selectedIndex != 0)
	{
		//Determine which drop-down select boxes are disabled
	    for (i=1; i<=ntakes; i++)
	    {
	        name = "text" + i;
	        if (document.getElementById(name).disabled == true)
	        {   // enable drop down
	            document.getElementById(name).disabled = false;
	            // get take kind id
	            takekind = "takekind" + i;
	            takekindID = document.getElementById(takekind).value;
	            alert("takeID: " + takeID + ", takekindID: " + takekindID);
	            // Call makeRequest() to see if I can read an html file
	            makeRequest(takeID, takekindID);
	        }
	    }
	}
	//alert("takeID: " + takeID + ", takekindID: " + takekindID);
}// end ValidateSel function

///////////////////////////////////////////////////////////////////////////////
//
//  Routine: getPath
//  
//  Purpose: Determine url path to page.
//
//  Parameters: 
//      page - *.asp file name
//
//  Returns: 
//      path.
// 
///////////////////////////////////////////////////////////////////////////////
function getPath(page)
{
	//	Build the location independent path using the current pages 
	//  address to compose a full path...
	dir = location.pathname;
	dir = dir.substring(1, dir.length);
	path = location.protocol + "//" + location.hostname;
	n = dir.indexOf("/");
	if (n != -1)
	{
		dir = dir.substring(0, n);
		path = path + "/" + dir;
	}
	path = path + "/" + page;
	return path;
}// end getPath

///////////////////////////////////////////////////////////////////////////////
//
//  Routine: makeRequest
//  
//  Purpose: Makes an HTTP request
//
//  Parameters: 
//      takeID     - currently selected Take ID from drop-down
//      takekindID - Take Kind ID from synced drop-down
//
//  Returns: 
//      Nothing.
// 
///////////////////////////////////////////////////////////////////////////////
function makeRequest(takeID, takekindID)
{
    http_request = false;

    if (window.XMLHttpRequest)
    { // Mozilla, Safari,...        
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject)
    { // IE
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {}
        }
    }

    if (!http_request)
    {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange = alertContents;
    var params = "TakeID="+takeID +"&TakeKindID="+takekindID;
    url = getPath("test2.asp");
    http_request.open('POST', url, true);
    http_request.setRequestHeader('Content-Type', 'application/x-[URL unfurl="true"]www-form-urlencoded');[/URL]
    http_request.send(params);
}// end makeRequest

///////////////////////////////////////////////////////////////////////////////
//
//  Routine: alertContents
//  
//  Purpose: Alerts contents of html page retrieved from an HTTP request
//
//  Parameters: 
//      Nothing - 
//
//  Returns: 
//      Nothing.
// 
///////////////////////////////////////////////////////////////////////////////
function alertContents()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200 || http_request.status == 0)
        {
            alert(http_request.responseText);
        }
        else
        {
            //alert("http_request.status: " + http_request.status);
            alert('There was a problem with the request.');
        }
    }
}// end alertContents


The objXML.Save method is creating response errors since I think it might having something to do with the request coming back to the javascript function. Any ideas would be greatly appreciated.

Thanks,
Todd
 
There shouldn't be any need to do the save at all since you are Response.Write'ing the content back to the browser.
The fact that it is coming back to the javascript function shouldn't really mater to the server, all it's doing is writing some data to the output buffer, it has no knowledge of whether it's going to be saved to a file, run through some javascript, etc.
Try taking the save out and, if yourr still getting an error, post the error you receiving.


 
Tarwyn,

Well, since I don't really have to save it persay. It's safe to assume that I'll be parsing the xml code in the same asp file that created the xml document? I'm just not sure about this. I thought it had to be a file, then open it, parse it and figure out how to populate the drop downs with the new data.

Todd
 
Not really. Just as the browser is receives an HTML "file" from the server (the usual output of an ASP script), your going to be sending it an XML "file" just by writing it to the response buffer and setting the content type to text/xml.
You can test that by just typing in the URL for your above page yourself (with a querystring value of course). Your browser will receive an XML file ven though it isn't saved anywhere on the server.
In the case of your javascript, it is using XMLHTTP objects to a do a browser request. So when your javascript executes (from any page) it will be acting as the browser above when you type the address in. You could embed your javascript functions in an HTML page and they would still work the same, since they are executing client-side and independant from the server-side code that is generating the XML.

The reason I was saying to take the save out is because it is unnecessary, especially if it s causing an error. You should try to run the ASP script once from the browser to see ifyou continue getting errors from the ASP page. If it outputs the XMl to the browser correctly then it is time to try and run the page with the javascript in it to make sure the javascript is getting the value correctly (should show up in your alert box).


 
You can test that by just typing in the URL for your above page yourself (with a querystring value of course). Your browser will receive an XML file ven though it isn't saved anywhere on the server." Well, I tested this like you said. Very cool.

I did take out the save as I don't need it. I believe the queries and javascript are ok. The javascript runs as an included file, not embedded on the asp page. The XML file looks like this:
Code:
<CanMsgSyncReq>
<TAKE_ID>15000</TAKE_ID>
<TAKE_DESCRIPTION>Northbound to</TAKE_DESCRIPTION>
<TAKE_ID>15001</TAKE_ID>
<TAKE_DESCRIPTION>Southbound to</TAKE_DESCRIPTION>
<TAKE_ID>15004</TAKE_ID>
<TAKE_DESCRIPTION>Northbound Service to</TAKE_DESCRIPTION>
<TAKE_ID>15005</TAKE_ID>
<TAKE_DESCRIPTION>Southbound Service to</TAKE_DESCRIPTION>
<TAKE_ID>15008</TAKE_ID>
<TAKE_DESCRIPTION>Northbound Service from</TAKE_DESCRIPTION>
<TAKE_ID>15009</TAKE_ID>
<TAKE_DESCRIPTION>Southbound Service from</TAKE_DESCRIPTION>
</CanMsgSyncReq>

The TAKE_DESCRIPTION would be the value seen in the drop-down box. The TAKE_ID would be the value that is stored when something is selected. So, would it be easy to parse. I haven't found any code yet, but I'm still looking.

Todd
 
Let me know what you find. The last time I was working with AJAXy stuff I got a little frustrted because the capabilities of the two browsers (IE + FF) are differant enough that I was having difficulties parsing the XML reliably. Obviously I overlooked something, but I was coding on a deadline and the AJAX part was an extra feature ;)

One thing you may want to do is look through the javascript forum. I'd be surprised if someone else hasn't posted up something yet.

Another option would be to use a pre-built set of tools like prototype.

-T

 
Tarwyn,

I'm trying to re-write the above XML document from the above style:
Code:
<?xml version="1.0"?>
<CanMsgSyncReq xmlns="x-schema: CanMsgSyncReqSchema.xml">
<TAKE_ID>15000</TAKE_ID>
<TAKE_DESCRIPTION>Northbound to</TAKE_DESCRIPTION>
<TAKE_ID>15001</TAKE_ID>
<TAKE_DESCRIPTION>Southbound to</TAKE_DESCRIPTION>
<TAKE_ID>15004</TAKE_ID>
<TAKE_DESCRIPTION>Northbound Service to</TAKE_DESCRIPTION>
<TAKE_ID>15005</TAKE_ID>
<TAKE_DESCRIPTION>Southbound Service to</TAKE_DESCRIPTION>
<TAKE_ID>15008</TAKE_ID>
<TAKE_DESCRIPTION>Northbound Service from</TAKE_DESCRIPTION>
<TAKE_ID>15009</TAKE_ID>
<TAKE_DESCRIPTION>Southbound Service from</TAKE_DESCRIPTION>
</CanMsgSyncReq>

into this style:
Code:
<?xml version="1.0"?>
<CanMsgSyncReq xmlns="x-schema: CanMsgSyncReqSchema.xml">
  <takes count="6">
    <take id="15000" description="Northbound to" />
    <take id="15001" description="Southbound to" />
    <take id="15004" description="Northbound Service to" />
    <take id="15005" description="Southbound Service to" />
    <take id="15008" description="Northbound Service from" />
    <take id="15009" description="Southbound Service from" />
  </takes>
</CanMsgSyncReq>

The new style would make it easier to parse. here's the vbscript that is used to create the xml.
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<!--#include file="include/database.asp"-->

<%  
    '--------------------------------------------------------------------------
    ' TakeID and TakeKindID being passed from makeRequest(takeID, takekindID)
    ' javascript function
    '--------------------------------------------------------------------------
    TakeID     = GetVal("TakeID", 0)
    TakeKindID = GetVal("TakeKindID", 0)
    
    'Dim strXMLFilePath, strFileName
    'Physical path of the root directory
    'strXMLFilePath = Server.MapPath("/")
    'Response.Write strXMLFilePath
    'strFileName = "CanMsgSync.xml"

    '--------------------------------------------------------------------------
    ' Create the XMLDOM Object that will hold the XML file
    '--------------------------------------------------------------------------
    Dim objXML
    set objXML = Server.CreateObject("Microsoft.XMLDOM")
    objXML.preserveWhiteSpace = True
    
    '--------------------------------------------------------------------------
    ' Check to see if objXML has data
    '--------------------------------------------------------------------------    
    If (objXML.childNodes.length = 0) Then

        '----------------------------------------------------------------------
        ' Create XML Document header
        '----------------------------------------------------------------------
	    set node = objXML.createProcessingInstruction("xml", "version='1.0'")
	    objXML.appendChild(node)	    
	    set root = objXML.createElement("CanMsgSyncReq")
	    set attrib = objXML.createAttribute("xmlns")
	    attrib.value = "x-schema: CanMsgSyncReqSchema.xml"
	    root.SetAttributeNode(attrib)
	    objXML.appendChild(root)
	    
	    '----------------------------------------------------------------------
        ' Determine Count of Take_ID's
        '----------------------------------------------------------------------
        Set cn = GetDBConnection()
        Set SQLStmt = Server.CreateObject("ADODB.Command")
        Set RS = Server.CreateObject("ADODB.Recordset")
        SQLStmt.CommandText = "SELECT DISTINCT COUNT(a.TAKE_ID) NUMTAKES " & _
                               "FROM LOCATION_TAKE_XREF_V a, LOCATION_TAKE_XREF_V b " & _
                               "WHERE a.LINE = (SELECT DISTINCT LINE FROM LOCATION_TAKE_XREF_V " & _
                               "                WHERE TAKE_ID = " & CStr(TakeID) & ")" & _
                               " AND   a.TAKE_KIND_ID = " & CStr(TakeKindID)          & _
                               " AND   b.TAKE_ID = " & CStr(TakeID)                   & _
                               " ORDER BY a.TAKE_ID ASC"
                               
        SQLStmt.CommandType = 1
        Set SQLStmt.ActiveConnection = cn
        RS.Open SQLStmt
        takeCount = RS("NUMTAKES")
        'Close Recordset
        RS.Close
	    
        '----------------------------------------------------------------------
        ' Determine Take_ID and Take_Description of synched drop down
        ' controls
        '----------------------------------------------------------------------
        Set cn = GetDBConnection()
        Set SQLStmt1 = Server.CreateObject("ADODB.Command")
        Set RS1 = Server.CreateObject("ADODB.Recordset")
        SQLStmt1.CommandText = "SELECT DISTINCT a.TAKE_ID, a.TAKE_DESCRIPTION "       & _
                               "FROM LOCATION_TAKE_XREF_V a, LOCATION_TAKE_XREF_V b " & _
                               "WHERE a.LINE = (SELECT DISTINCT LINE FROM LOCATION_TAKE_XREF_V " & _
                               "                WHERE TAKE_ID = " & CStr(TakeID) & ")" & _
                               " AND   a.TAKE_KIND_ID = " & CStr(TakeKindID)          & _
                               " AND   b.TAKE_ID = " & CStr(TakeID)                   & _
                               " ORDER BY a.TAKE_ID ASC"
                               
        SQLStmt1.CommandType = 1
        Set SQLStmt1.ActiveConnection = cn
    
        RS1.Open SQLStmt1
        Do While Not RS1.EOF
 
            '------------------------------------------------------------------
            ' Create XML document node and elements
            '------------------------------------------------------------------            
            set node = objXML.createElement("TAKE_ID")
            node.text = RS1("TAKE_ID")
            root.appendChild(node)
            
            set node = objXML.createElement("TAKE_DESCRIPTION")
            node.text = RS1("TAKE_DESCRIPTION")
            root.appendChild(node)
            
            RS1.MoveNext
        Loop
        RS1.Close
        
        Set RS1 = Nothing
    
    cn.Close
    Set cn = Nothing
    
    '--------------------------------------------------------------------------
    ' Save the XML doc
    '--------------------------------------------------------------------------
    'objXML.Save(strXMLFilePath & "\" & strFileName)
	
    '--------------------------------------------------------------------------
    ' Create and Send XML Response
    '--------------------------------------------------------------------------
	Response.ContentType="text/xml"
    Response.Write(objXML.xml)
        
    End If
%>

So, I've been trying to fool around with the elements and node attributes. So far, I have not been successful. Just wanted to get some ideas.

Thanks,
Todd
 
I was able to get the new style implemented. A little persistence pays off. :)

Code:
 '------------------------------------------------------------------
            ' Create XML document <take> elements
            '------------------------------------------------------------------
            set node = objXML.createElement("take")
            set attrib = objXML.createAttribute("id")
            attrib.value = RS1("TAKE_ID")
            node.SetAttributeNode(attrib)
            root.appendChild(node)
            
            set attrib = objXML.createAttribute("description")
            attrib.value = RS1("TAKE_DESCRIPTION")
            node.SetAttributeNode(attrib)
            root.appendChild(node)

Todd
 
Nice, Sorry I didn't respond. I had started a post at work yesterday afternoon and apparently never hit the submit button. Course I actually feel good about that, because I thought you were talking about the client-side portion and was going completely down the wrong trail with my post ;)

 
tarwyn,

I've been able to construct a rather simple xml parser for each xml response. I'm in the middle of trying to take each xml element and use it to update the values on a drop-down box. I need to do this every time the 1st drop-down value changes. I have several drop-down that need to be linked and I am still thinking about hwo to do just that. Right now, I only have xml responses occuring after the page first loads and when all drop-downs are disabled except for the 1st one. So, I still have some work to do.

Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top