aspx and xml Attributes

Posted by Rhewston under XML on 3/31/2011 | Points: 10 | Views : 1811 | Status : [Member] | Replies : 1
I am using aspx to send a XML request to an 'engine' which will send me back a response:
<%
Dim URL
Dim XMLHTTP
Dim sRequest
Dim sServerNode
Dim URLEncoder
Dim result

'**** XML Data ****
sRequest = "<eLoginRequest ClientType='Win32' CurrentSAP='0' Locale='eng'><FieldInputList><FieldInput Field='username'>Richard</FieldInput><FieldInput Field='password'>D41D8CD98F00B204E9800998ECF8427E</FieldInput></FieldInputList></eLoginRequest>"
sServerNode = "<Engine Name='Engine'><Transport Type='DCOM'><Server>localhost</Server></Transport></Engine>"

'**** Engine URL ****
url = "http://localhost/escripts/eMessageHandler.dll"

xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open ("Get", url, false)
xmlhttp.send ("ServerNode=" & Server.URLEncode(sServerNode) & "&Request=" & Server.URLEncode(sRequest))

**** Writes the XML response to the page *****
Response.write (xmlhttp.responseText)

**** To be used to get the XML Attributes *****
xmlDoc= xmlhttp.responseXML

%>

The XML Response sent back is:

<eLoginResponse Timestamp="2011-03-31T16:01:24" SessionID="BCFEC70C-55CD-45A2-A34C-60301EEB7D5C" OldestDeletion="2011-03-21T21:31:10" UserID="Richard"><ClientData/></eLoginResponse>

What I want to do is display the attribute: 'SessionID' on the screen, either assign the session ID value to a variable or to a text box value. So far I am using the code below but I am stuck on how this can be done:

<%
dim xmlDoc
dim i

xmlDoc= xmlhttp.responseXML
dim x = xmlDoc.getElementsByTagName("SessionID")
Response.write(x)

%>

The code above will print the following to the screen: System.__ComObject
I have also tried using x.xmlObj.childNodes(0).getAttribute("SessionID") but I get the following error: Identifier expected.





Responses

Posted by: Ndebata on: 4/13/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

Try to use LINQ

using System.Xml.Linq;

Then Load/Parse based on you case by
XElement xe=XElement.Parse(xmlhttp.responseXML);
or
XElement xe=XElement.Load(xmlhttp.responseXML);

Then
use xe.Attribute("SessionID").Value

Thanks,
Debata





Rhewston, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response