Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 reading xml
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jezmeister
Senior Member

United Kingdom
1141 Posts

Posted - 08 October 2009 :  07:32:36  Show Profile  Visit Jezmeister's Homepage  Reply with Quote
I've been using the code below to read xml feeds for a while - iirc it's straight from the microsoft website anyway not my own work:

Dim adoRS       'ADODB.Recordset
    Set adoRS =  CreateObject("ADODB.Recordset")
  
    
    ' Set up the Connection
    adoRS.ActiveConnection = "Provider=MSDAOSP; Data Source=MSXML2.DSOControl.2.6;"
     
    ' Open the XML source
    adoRS.Open Server.MapPath(".") & "\portfolio.xml"
    
    printtbl adoRS, 0
    
    If adoRS.State = adStateOpen Then
        adoRS.Close
    End If
    Set adoRS = Nothing
    Response.End 

' Function to recurcusively retrieve the data
Sub printtbl(rs, indent)
        
    Dim rsChild         'ADODB.Recordset
    Dim Col             'ADODB.Field
    
    set rsChild = Server.CreateObject("ADODB.Recordset")
   
    While rs.EOF <> True
        For Each Col In rs.Fields
            If Col.Name <> "$Text" Then   ' $Text to be ignored
                If Col.Type <> adChapter Then
                    ' Output the non-chaptered column
                    Response.Write( String((indent)," " )  & Col.Name & ": " & Col.Value )
                Else
                    Response.Write("<br/>")
                    ' Retrieve the Child recordset
                    Set rsChild = Col.Value
                    rsChild.MoveFirst
                    If Err Then 
                        Response.write("Error: " &  Error ) 
                        Response.end
                    end if     
                    printtbl rsChild, indent + 4
                    rsChild.Close
                    Set rsChild = Nothing
                End If
            End If
        Next
        Response.Write( "<br/>")
        rs.MoveNext
    Wend
    
End Sub


Now, generally that works fine, however I'm now trying to read a feed with this content:

<Track>
	<Name>Lander Raceway</Name>
	<Country id="12">Australia</Country>
	<Laps>53</Laps>
	<TotalParts>18</TotalParts>
	<RaceStartTime>18</RaceStartTime>
	<PitlaneLength>Medium</PitlaneLength>
	<WearTyres>Big</WearTyres>
	<WearFuel>Big</WearFuel>
</Track>


I get a type mismatch when it gets to country id="12", and I have no way of changing that source file - I have tried using Replace to remove the offending ' id="12"' before it's used but with no luck - any ideas? I suppose keeping the id info would be a useful lesson but removing it would be a good enough fix.

thanks in advance :)
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.23 seconds. Powered By: Snitz Forums 2000 Version 3.4.07