March 11th, 2003, 06:15 AM
-
variable dissapearing!
Hi,
I'm using ASP to retrieve simple information from an XML file. I set a variable on the asp page that gets the information from XML if they match.
It is supposed to write out the answer but for some reason the variable on the asp page is not matching the value on the XML page even though they are the same.
Code:
<%
Var1 = 3
response.write "CD: "
response.write Var1 & "<BR>"
' open xml file to compare
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.Load(Server.MapPath("check.xml"))
Set objLst = objXML.getElementsByTagName("list")
intNoOfHeadlines = objLst.length
For i = 0 To intNoOfHeadlines-1
'the code below is not matching
if objLst.item(i).childNodes(0).text = Var1 then
response.write objLst.item(i).childNodes(1).text
response.write " category is selected"
end if
Next
%>
the xml file
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Menu>
<list>
<cd>1</cd>
<category>6</category>
</list>
<list>
<cd>2</cd>
<category>6</category>
</list>
<list>
<cd>3</cd>
<category>7</category>
</list>
<list>
<cd>4</cd>
<category>8</category>
</list>
</Menu>
Var1 = 3 and there is a tag with value 3 in the xml so its suposed to print out childnode(1) which is 7.
The weird thing is if i use the line
Code:
if objLst.item(i).childNodes(0).text = 3
instead of
Code:
if objLst.item(i).childNodes(0).text = Var1
it works but i want to be able to have the value in a variable.
Can anyone help? Thanks.
"They have the internet on computers now" - Homer
March 21st, 2003, 12:47 AM
-
The reason you are not getting a match is that the statement
Var1 = 3
sets Var1 to numeric 3, whereas the string you are comparing to is text. Numeric 3 and text 3 are not the same. So try one of the following, declare Var1 as text by using
Var1 = "3"
Or try accessing Var1 as text using
Var1.text
One of these should work.
How can I soar like an eagle when
I'm flying with turkey's?
March 26th, 2003, 05:22 AM
-
"They have the internet on computers now" - Homer