Displaying XML

  • Thread starter Christopher Brandsdal
  • Start date
C

Christopher Brandsdal

Hi!

I have problems displaying a XML-file the way i want on my website.
This is the link to the file I have to display(ps: the file is on a remote
server, so I have to the file via http or something):
http://www.telenor.turnpike.no/voting/rakfiskfestival/public/status.xml

I want to display the data in my own designed HTML-code. One of the big
challanges to insert the "percent" field in the XML-file into the width="x%"
field in the HTML TD.
I have tried XSLT and lots of other things in VS2005, but I can't seem to
fin any solutin. This might be easy, but I'm a newb to XML ;-)

Here is the HTML-code i want the XML data to be inserted into:
(The fields from the XML-file is marked ### FieldName ###)


------------------------------------------------------------------------------------
<table width="360" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="115" height="25"><strong>### id ###</strong></td>
<td width="50" height="25"><em>(### count ###)</em></td>
<td width="195" height="25"><table width="195" height="12" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td width="### percent ###" bgcolor="#b4003c">&nbsp;</td>
<td bgcolor="#fcedd9">&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
------------------------------------------------------------------------------------

If anyone know how to do this, I would love to hear abot it :)

Best regards,
Christopher Brandsdal
 
C

Christopher Brandsdal

I turned my head around, and came up with something that worked great.
Might not be the best code LOL ;-)

<%@ Import Namespace="System.Xml" %>
<script language="VB" runat=server>

sub Page_Load(Sender as Object, e as EventArgs)

dim reader as XMLTextReader

Response.Write("<table width='360' border='0' cellspacing='0'
cellpadding='0'>")

try

reader = New
XmlTextReader("http://www.telenor.turnpike.no/voting/rakfiskfestival/public/status.xml")


While reader.Read()

Select Case reader.NodeType

Case XMLNodeType.Element

if reader.HasAttributes then

If reader.AttributeCount = 2 Then

Else

If reader.GetAttribute(0) = "none" Then

Else

Response.Write("<tr>" & vbCrLf)

Response.Write("<td width='115' height='25'>" & vbCrLf)

Response.Write("<strong>" & vbCrLf)

Select Case reader.GetAttribute(0)

Case "1"

Response.Write("example 1" & vbCrLf)

Case "2"

Response.Write("example 2" & vbCrLf)

Case Else

Response.Write("default example" & vbCrLf)

End Select

Response.Write("</strong>" & vbCrLf)

Response.Write("</td>" & vbCrLf)

Response.Write("<td width='50' height='25'>" & vbCrLf)

Response.Write("<em>" & vbCrLf)

Response.Write(reader.GetAttribute(1))

Response.Write("</em>" & vbCrLf)

Response.Write("</td>" & vbCrLf)

Response.Write("<td width='195' height='25'>" & vbCrLf)

Response.Write("<table width='195' height='12' border='0' cellpadding='0'
cellspacing='0'>" & vbCrLf)

Response.Write("<tr>" & vbCrLf)

Response.Write("<td width='" & reader.GetAttribute(2) & "'
bgcolor='#b4003c'>&nbsp;" & vbCrLf)

Response.Write("</td>" & vbCrLf)

Response.Write("<td bgcolor='#fcedd9'>&nbsp;</td>" & vbCrLf)

Response.Write("</tr>" & vbCrLf)

Response.Write("</table>" & vbCrLf)

Response.Write("</td>" & vbCrLf)

Response.Write("</tr>" & vbCrLf)

End If

End If

End If

End Select

End While

catch ex as Exception

Response.Write("Error accessing XML file")

finally

reader.close

end try

Response.Write("</table>")

end sub

</script>

<html><body>

</body></html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top