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

Need Help ASAP - Retrieving Values from XML using DOM in ASP 1

Status
Not open for further replies.

FireFett

Programmer
Mar 31, 2000
42
US
I have an XML Doc that stores Query Parameters.

<?xml version="1.0" ?>
<?xml-stylesheet type='text/xml' href='test.xsl'?>
- <!-- sample xml file created using XML DOM object.
-->
- <Parameters created="using dom">
<UserID>Chris</UserID>
<PWD>Pass</PWD>
</Parameters>


and I have an ASP page that needs to read those parameters

<%


Dim xml

Set xml = Server.CreateObject("Microsoft.XMLDOM")

xml.load("F:\SMS\ASP\Test.XML")


dim UserID
'find the node that we want and put it's value in a variable
UserID = xml.getElementsByTagName("//Parameters/UserID").item(0).text
response.Write("UserID: " & UserID)

Set xml = Nothing
%>

The line that gives me a problem is UserID = xml.getElementsByTagName...

Can any one help???
 
try this


UserID = xml.getElementsByTagName("//Parameters/UserID")
response.Write("UserID: " & UserID.item(0).text)

 
Thanks but that isn't it the problem that is generated is

msxml3.dll (0x80004005)
Unexpected token '//'. .//-->//<--Parameters/UserID
/Test/ValidateLogin.asp, line 17
 
Er... can getElementsByTagName() use xpath stuff? I think it is limited to single tag name and "*".
Btw. what about .selectNodes()?
 
I can use .getElementsByTagName() using an Xpath in vb 6 just fine so why would it fail in asp? in vb I am referencing msxml4 would that cause the problem?
 
Thanks vongrunt.

Appearently vb script does not like the .getElements using Xpath so I tried the .SelectNodes and it works like a champ.





 
Actually, VBScript does like using .getElements using xpath. The error above explains tat it doesn't like the preceding double slashes, if you remove those it should work just fine.

If you read the line carefully you'll notice that the function adds in the double slashes on it's own:
//-->//<--Parameters/UserID

those first two slashes have been added by the function automatically. I would have written the function to only add them if they weren't already present, but apparently someone at MS is lazy and just assumed none of us would put the double slashes on the front ourselves.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
I'm new to XML and I'm having trouble storing the values of XML elements into ASP variables, similar to this thread.

The XML that I'm trying to parse is:

<?xml version="1.0" encoding="UTF-8"?>
<GeteBayOfficialTimeResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2005-08-12T02:33:09.184Z</Timestamp>
<Ack>Success</Ack>
<CorrelationID>00000000-00000000-00000000-00000000-00000000-00000000-0000000000</CorrelationID>
<Version>421</Version>
<Build>e421_core_Bundled_1630320_R1</Build>
</GeteBayOfficialTimeResponse>

I'd like to store the values of each child element into ASP variables...for now I'm just working with Timestamp. What I've tried is:

xmlNamespace = "urn:ebay:apis:eBLBaseComponents:"
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.load("92557PM.xml")

Dim Timestamp
Timestamp = xmlDoc.getElementsByTagName("GeteBayOfficialTimeResponse/"&xmlNamespace&"Timestamp")
response.Write("Timestamp: " & Timestamp.item(0).text)


That's returning error: .//GeteBayOfficialTimeResponse/urn:ebay-->:<--apis:eBLBaseComponents:Timestamp

Any information on what I need to do to make this work would be greatly appreciated. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top