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

    Join Date
    Nov 2001
    Posts
    544
    Rep Power
    38

    XML getattributes


    Hi, i have this simple script i got from the net that is used to parse XML with ASP. It uses the "getattributes" function to get information from xml tags....
    xml
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <States> 
    <State ref="FL" const="27"> 
    <name>Florida</name> 
    <capital>Tallahassee</capital> 
    </State> 
    <State ref="IA" const="29"> 
    <name>Iowa</name> 
    <capital>Des Moines</capital> 
    </State> 
    </States>
    asp..
    Code:
    <%
    set XMLDoc = Server.CreateObject("Microsoft.XMLDOM")
    XMLDoc.async = false
    XMLDoc.load("test.xml") 
    set states = XMLDoc.getElementsByTagName("State")
    
    n_states = states.length
    
    for i = 0 to n_states-1
    
    Set state = states.item(i)
    response.write state.getAttribute("ref")
    response.write "<br>"
    
    next
    %>
    Nothing is printed out in the ASP page even though according to the script i should get "FL IA" printed out. The problem seems to be that its not finding any tages called 'State'. If you print out "response.write n_states", the result is zero. Does anyone know where its going wrong? Thanks.
    "They have the internet on computers now" - Homer
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    8
    Rep Power
    0
    If your code is exactly as you've written, the problem may be because XML is case-sensitive. Your <state> tag should be all in lower case instead of <State>. XML generally ignores tags it doesn't recognize, so that may be why you're not getting an error message. Hope this helps.

    Comments on this post

    • Gran Roguismo agrees

IMN logo majestic logo threadwatch logo seochat tools logo