Jump to content
Sign in to follow this  
Tbonekiller

Bind xml to html

Recommended Posts

Hi all..I am runing a cs:s server and i am generation a xls file from a stats.txt file every 30 min.. Can anyone tell me how to show to file via a html... I´ve tryed to run a example on my website but i cant get it working... I have placed the html and xml file in the same folder on the web site... HTML:<html><head><script type="text/javascript">function testclick(field){var row=field.rowIndexxmldso_list.recordset.absoluteposition=rowtd_title.innerHTML=xmldso_list.recordset("TITLE")td_artist.innerHTML=xmldso_list.recordset("ARTIST")td_year.innerHTML=xmldso_list.recordset("YEAR")td_country.innerHTML=xmldso_list.recordset("COUNTRY")td_company.innerHTML=xmldso_list.recordset("COMPANY")td_price.innerHTML=xmldso_list.recordset("PRICE")}</script></head><body><xml id="xmldso_list" src="cd_catalog.xml"></xml><table border="1" bgcolor="yellow"><tr align="left"><th>Title: </th><td id="td_title"></td></tr><tr align="left"><th>Artist: </th><td id="td_artist"></td></tr><tr align="left"><th>Year: </th><td id="td_year"></td></tr><tr align="left"><th>Country:</th><td id="td_country"></td></tr><tr align="left"><th>Company:</th><td id="td_company"></td></tr><tr align="left"><th>Price: </th><td id="td_price"></td></tr></table><p><b>Click on one of the CDs in the list:</b></p><table datasrc="#xmldso_list" border="1"><thead><tr align="left"><th>Title</th><th>Artist</th><th>Country</th><th>Company</th><th>Price</th><th>Year</th></tr></thead><tr align="left" onclick="testclick(this)"><td><div datafld="TITLE" /></td><td><div datafld="ARTIST" /></td><td><div datafld="COUNTRY" /></td><td><div datafld="COMPANY" /></td><td align="right"><div datafld="PRICE" /></td><td><div datafld="YEAR" /></td></tr></table></body></html>XML:?xml version="1.0" encoding="ISO-8859-1" ?> - <!-- Edited with XML Spy v2006 (http://www.altova.com) --> - <CATALOG>- <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD>- <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD>- <CD> <TITLE>Greatest Hits</TITLE> <ARTIST>Dolly Parton</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>RCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1982</YEAR> </CD>- <CD> <TITLE>Still got the blues</TITLE> <ARTIST>Gary Moore</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin records</COMPANY> <PRICE>10.20</PRICE> <YEAR>1990</YEAR> </CD>- <CD> <TITLE>Eros</TITLE> <ARTIST>Eros Ramazzotti</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>BMG</COMPANY> <PRICE>9.90</PRICE> <YEAR>1997</YEAR> </CD>- <CD> <TITLE>One night only</TITLE> <ARTIST>Bee Gees</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>10.90</PRICE> <YEAR>1998</YEAR> </CD>- <CD> <TITLE>Sylvias Mother</TITLE> <ARTIST>Dr.Hook</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS</COMPANY> <PRICE>8.10</PRICE> <YEAR>1973</YEAR> </CD>- <CD> <TITLE>Maggie May</TITLE> <ARTIST>Rod Stewart</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Pickwick</COMPANY> <PRICE>8.50</PRICE> <YEAR>1990</YEAR> </CD>- <CD> <TITLE>Romanza</TITLE> <ARTIST>Andrea Bocelli</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>10.80</PRICE> <YEAR>1996</YEAR> </CD>- <CD> <TITLE>When a man loves a woman</TITLE> <ARTIST>Percy Sledge</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>8.70</PRICE> <YEAR>1987</YEAR> </CD>- <CD> <TITLE>Black angel</TITLE> <ARTIST>Savage Rose</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Mega</COMPANY> <PRICE>10.90</PRICE> <YEAR>1995</YEAR> </CD>- <CD> <TITLE>1999 Grammy Nominees</TITLE> <ARTIST>Many</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Grammy</COMPANY> <PRICE>10.20</PRICE> <YEAR>1999</YEAR> </CD>- <CD> <TITLE>For the good times</TITLE> <ARTIST>Kenny Rogers</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Mucik Master</COMPANY> <PRICE>8.70</PRICE> <YEAR>1995</YEAR> </CD>- <CD> <TITLE>Big Willie style</TITLE> <ARTIST>Will Smith</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>9.90</PRICE> <YEAR>1997</YEAR> </CD>- <CD> <TITLE>Tupelo Honey</TITLE> <ARTIST>Van Morrison</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>8.20</PRICE> <YEAR>1971</YEAR> </CD>- <CD> <TITLE>Soulsville</TITLE> <ARTIST>Jorn Hoel</ARTIST> <COUNTRY>Norway</COUNTRY> <COMPANY>WEA</COMPANY> <PRICE>7.90</PRICE> <YEAR>1996</YEAR> </CD>- <CD> <TITLE>The very best of</TITLE> <ARTIST>Cat Stevens</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Island</COMPANY> <PRICE>8.90</PRICE> <YEAR>1990</YEAR> </CD>- <CD> <TITLE>Stop</TITLE> <ARTIST>Sam Brown</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>A and M</COMPANY> <PRICE>8.90</PRICE> <YEAR>1988</YEAR> </CD>- <CD> <TITLE>Bridge of Spies</TITLE> <ARTIST>T'Pau</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Siren</COMPANY> <PRICE>7.90</PRICE> <YEAR>1987</YEAR> </CD>- <CD> <TITLE>Private Dancer</TITLE> <ARTIST>Tina Turner</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Capitol</COMPANY> <PRICE>8.90</PRICE> <YEAR>1983</YEAR> </CD>- <CD> <TITLE>Midt om natten</TITLE> <ARTIST>Kim Larsen</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Medley</COMPANY> <PRICE>7.80</PRICE> <YEAR>1983</YEAR> </CD>- <CD> <TITLE>Pavarotti Gala Concert</TITLE> <ARTIST>Luciano Pavarotti</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>DECCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1991</YEAR> </CD>- <CD> <TITLE>The dock of the bay</TITLE> <ARTIST>Otis Redding</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>7.90</PRICE> <YEAR>1987</YEAR> </CD>- <CD> <TITLE>Picture book</TITLE> <ARTIST>Simply Red</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Elektra</COMPANY> <PRICE>7.20</PRICE> <YEAR>1985</YEAR> </CD>- <CD> <TITLE>Red</TITLE> <ARTIST>The Communards</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>London</COMPANY> <PRICE>7.80</PRICE> <YEAR>1987</YEAR> </CD>- <CD> <TITLE>Unchain my heart</TITLE> <ARTIST>Joe Cocker</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>EMI</COMPANY> <PRICE>8.20</PRICE> <YEAR>1987</YEAR> </CD> </CATALOG>Shoulden´t this be working??? When I enter my site the only thing i can see is the html, why isin´t the xml file filling in the things...Sorry my english.... Hope some one can help....

Share this post


Link to post
Share on other sites

Well, for starters, your XML is not valid. See all the "-" in front of the <CD> elements? They shouldn't be there. When you see the file, click "View Source" the same way you do for HTML pages and you'll see the actual XML code.Another thing is that Data Islands (the method you're using) works only with IE. If you're using ANY OTHER browser, it won't work.Why do you need the JavaScript for, anyway?

Share this post


Link to post
Share on other sites

In your xml document, add < tag in the first line.

<?xml version="1.0" encoding="ISO-8859-1" ?>

Then take out all the - in front of the CD, it should work fine.

-<CD>

Share this post


Link to post
Share on other sites

I am using an IIS web server. Does IIS have to be configured in any particular way for XML files to be grabbed? I ask this because my html file works perfectly when the binding points to the W3school catalog in the example. But when I put the xml file containing the catalog on my server, the html file does not seem to be able to grab the xml data. Oh, and I am pointing at my own IIS server in the HTML code.Thank you.

Share this post


Link to post
Share on other sites
I am using an IIS web server.  Does IIS have to be configured in any particular way for XML files to be grabbed?  I ask this because my html file works perfectly when the binding points to the W3school catalog in the example.  But when I put the xml file containing the catalog on my server, the html file does not seem to be able to grab the xml data. Oh, and I am pointing at my own IIS server in the HTML code.Thank you.

I dont think it should be a problem becoz i tried and it worked for me.

Share this post


Link to post
Share on other sites
In your xml document, add < tag in the first line.
<?xml version="1.0" encoding="ISO-8859-1" ?>

Then take out all the - in front of the CD, it should work fine.

-<CD>

Thx jojay...Thats was my problem, now I just need to figure out hew to get my gamestats.xml displayed via html, atleast I got the exampel working now "thx to you"..

Share this post


Link to post
Share on other sites

Hi again...Okey.. This is my server_stats.xml<?xml-stylesheet type="text/xsl" href="whiteness.xsl"?><mani_stats> <plugin_version>"mani_stats.txt"</plugin_version> <stats_created> <year>2006</year> <month>4</month> <day>26</day> <hour>19</hour> <minute>14</minute> <second>35</second> </stats_created> <user> <steam_id>{"version" "V1.2BetaN RC1""1"{"na" "(SVB)Tbonekiller""st" "STEAM_0:1:1163382""ip1" "10""ip2" "0""ip3" "0""ip4" "2""lc" "1148572704""rwhiteness.xsl</steam_id> <name>killer""st" "STEAM_0:1:1163382""ip1" "10""ip2" "0""ip3" "0""ip4" "2""lc" "1148572704""rwhiteness.xsl</name> <kills>153236592</kills> <deaths>170013218</deaths> <suicides>576941090</suicides> <headshots>825303561</headshots> <kd_ratio>0.000011</kd_ratio> <last_connected> <year>1997</year> <month>8</month> <day>30</day> <hour>1</hour> <minute>18</minute> <second>10</second> </last_connected> </user> <user> <steam_id>k" "1""de" "5""hs" "4""kd" "1.200000""ki" "6""su" "0""po" "1010.458862""pd" "0.000000""tk" "0""to" "2179""da" "1273""hh" "6""hc" "13whiteness.xsl</steam_id> <name>"su" "0""po" "1010.458862""pd" "0.000000""tk" "0""to" "2179""da" "1273""hh" "6""hc" "13whiteness.xsl</name> <kills>153248100</kills> <deaths>926036258</deaths> <suicides>571089459</suicides> <headshots>153249896</headshots> <kd_ratio>0.000000</kd_ratio> <last_connected> <year>1988</year> <month>3</month> <day>13</day> <hour>15</hour> <minute>7</minute> <second>46</second> </last_connected> </user></mani_stats>Could someone make a small example html, how to get these figures på in to a table. just a very small one so I can get the basics.. I was hoping to be able to edit the cd_catalog example html, but I can´t get it to display anything from the server_stats.xml though I have changed <xml id="xmldso_list" src="cd_catalog.xml"></xml>to<xml id="xmldso_list" src="server_stats.xml"></xml> <xml id="xmldso_list" is just a call name for the xml file in the html isin´t it? Thx..

Share this post


Link to post
Share on other sites

As far as I can see in the XML, you're using XSLT to transform it. So why is the need for Data Islands anyway? Stick with the XSLT. You can use JavaScript to execute the XSLT within the HTML, so it would look the same.As for why the Data Islands don't work, it's probably inconsistent naming scheme. In order for Data Islands to work, all of your desired info must be structured accordingly, not in some weird text-like way you have done. The way this XML looks, it would never work with Data Islands. It could be however usefull with XSLT though. I suggest you forget about Data Islands anyway. Dealing with inconsistent naming schemes is only the first reason for why they are bad.

Share this post


Link to post
Share on other sites
I dont think it should be a problem becoz i tried and it worked for me.

Turns out there were garbage characters at the beginning of my XML file that did not show up in a simple text editor. I used a hexeditor to examine the file. I discovered this when I tried to open the XML file with IE. IE complained about the first statement not being recognizable. Once the XML file was able to be opened with IE, the XML Binding of the Data Island worked fine.

Share this post


Link to post
Share on other sites
Hi again..Is it possible at all to make anything out of this server_stats.xml??

If you are trying Data Island using javascript just like the previous one, then it should be something like the one below. I have worked out a sample code:xml file:
<?xml version="1.0" encoding="ISO-8859-1" ?><mani_stats>        <User>     	 <steam_id>{	"version" "V1.2BetaN RC1"	"1"	{	"na" "(SVB)Tbonekiller"	"st" "STEAM_0:1:1163382"	"ip1" "10"	"ip2" "0"	"ip3" "0"	"ip4" "2"	"lc" "1148572704"	"rwhiteness.xsl	</steam_id>		<name>killer"	"st" "STEAM_0:1:1163382"	"ip1" "10"	"ip2" "0"	"ip3" "0"	"ip4" "2"	"lc" "1148572704"	"rwhiteness.xsl	</name>	<kills>153236592</kills>	<deaths>170013218</deaths>	<suicides>576941090</suicides>	<headshots>825303561</headshots>	<kd_ratio>0.000011</kd_ratio>		      </User>      <User>	<steam_id>k" "1"	"de" "5"	"hs" "4"	"kd" "1.200000"	"ki" "6"	"su" "0"	"po" "1010.458862"	"pd" "0.000000"	"tk" "0"	"to" "2179"	"da" "1273"	"hh" "6"	"hc" "13whiteness.xsl	</steam_id>	<name>"su" "0"	"po" "1010.458862"	"pd" "0.000000"	"tk" "0"	"to" "2179"	"da" "1273"	"hh" "6"	"hc" "13whiteness.xsl	</name>	<kills>153248100</kills>	<deaths>926036258</deaths>	<suicides>571089459</suicides>	<headshots>153249896</headshots>	<kd_ratio>0.000000</kd_ratio>	      </User></mani_stats>

html file:

<html><head><script type="text/javascript">function testclick(field){var row=field.rowIndexxmldso_list.recordset.absoluteposition=rowtd_steam_id.innerHTML=xmldso_list.recordset("steam_id")td_name.innerHTML=xmldso_list.recordset("name")td_kills.innerHTML=xmldso_list.recordset("kills")td_deaths.innerHTML=xmldso_list.recordset("deaths")td_suicides.innerHTML=xmldso_list.recordset("suicides")td_headshots.innerHTML=xmldso_list.recordset("headshots")td_kd_ratio.innerHTML=xmldso_list.recordset("kd_ratio")}</script></head><body><xml id="xmldso_list" src="stats.xml"></xml><table border="1" bgcolor="#cc3300" ><tr align="left"><th>Steam_id: </th><td id="td_steam_id"></td></tr><tr align="left"><th>Name: </th><td id="td_name"></td></tr><tr align="left"><th>Kills: </th><td id="td_kills"></td></tr><tr align="left"><th>Deaths: </th><td id="td_deaths"></td></tr><tr align="left"><th>Suicides: </th><td id="td_suicides"></td></tr><tr align="left"><th>Headshots:</th><td id="td_headshots"></td></tr><tr align="left"><th>Kd_ratio:</th><td id="td_kd_ratio"></td></tr></table><p><b>Click on one of the CDs in the list:</b></p><table datasrc="#xmldso_list" border="1"><thead><tr align="left"><th>Steam_id</th><th>Name</th><th>Kills</th><th>Deaths</th><th>Suicides</th><th>Headshots</th><th>Kd_ratio</th></tr></thead><tr align="left" onclick="testclick(this)"><td><div datafld="steam_id" /></td><td><div datafld="name" /></td><td><div datafld="kills" /></td><td><div datafld="deaths" /></td><td><div datafld="suicides" /></td><td><div datafld="headshots" /></td><td><div datafld="kd_ratio" /></td></tr></table></body></html>

Share this post


Link to post
Share on other sites

Hi Jojay...Thank you for helping out...I think my problem is the TXT to XML generetor, The output xml is useless..It is working fine when I am yousing your examples, but there is a lot useless information...I guess I just have to keep looking for a solution..Thx anyway.. Thomas..

Share this post


Link to post
Share on other sites

I agree with Boen (who is now my involuntary mentor!), but what I'd say is if you want to show the xml using your own html, dont use data islands and instead copy your html into your style sheet and replace the XML data links with <xsl:for-each>.for example:

<table><thead><tr align="left"><th>Steam_id</th><th>Name</th><th>Kills</th><th>Deaths</th><th>Suicides</th><th>Headshots</th><th>Kd_ratio</th></tr></thead><xsl:for-each select="User"><tr align="left" onclick="testclick(this)"><td><xsl:value-of select="steam_id" /></td><td><xsl:value-of select="name" /></td><td><xsl:value-of select="kills" /></td><td><xsl:value-of select="deaths" /></td><td><xsl:value-of select="suicides" /></td><td><xsl:value-of select="headshots" /></td><td><xsl:value-of select="kd_ratio" /></td></tr></xsl:for-each></table>

Then all you need to do is apply the stylesheet, which is something you can do in either XMLDOM (javascript) or within the XML file itself.You seriously need to look at the XSL tutorial first though - it's great and you can see where you've gone wrong when you try stuff out.

A computer is a tool like any other, as long as you use it correctly it'll work correctly!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...