#1
  1. No Profile Picture
    php newbie
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    544
    Rep Power
    37

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Melbourne, Australia
    Posts
    212
    Rep Power
    12
    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?
  4. #3
  5. No Profile Picture
    php newbie
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    544
    Rep Power
    37
    Thanks man! it works.
    "They have the internet on computers now" - Homer

IMN logo majestic logo threadwatch logo seochat tools logo